简体   繁体   中英

Form validation for dynamically added fields in react

I have created a form in react which has 2 fields. After clicking add button it adds same 2 more fields. Now I want to validate those fields. Can anyone help me please.

Codesandbox link : https://codesandbox.io/s/react-dynamic-form-fields-9fzzh

Your question is a little incomplete. First, tell me which field you want to validate and what you have tried till now. For reference you can check this site: here

There are a couple of ways you can do this. The standard up until recently has been using a large yup schema with conditional validation (using 'when').

I made a library called Fielder specifically for dynamic field-level validation such as in your example. It prevents the need to use a large schema and provide conditions up front.

Check out the second two examples on this page which dynamically add validation criteria as the user progresses through the form.

Check out the Fielder repo and let me know if it works out for you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM