redux-form-validation-with-fieldarray
Easy validation for redux-form's fields(** And support FieldArray **)
Installation
npm:
npm install redux-form-validation-with-fieldarray
yarn:
yarn add redux-form-validation-with-fieldarray
Example
You can pass a function and access to values (maybe needed) or pass an array with validation functions.
You can write your custom functions.
You can access to another values from a field.
Note: if you want pass a function, your function should return an array.
We have two validations example:
; const validate = ;;
This is an example that how you can access to form values:
; const validate = ;;
And in your form component:
;;;;;; @ static propTypes = handleSubmit: PropTypesfunc ; { const handleSubmit = thisprops; return <form> <div> <Field name="firstname" component=Input placeholder="firstname" /> <Field name="lastname" component=Input placeholder="lastname" /> </div> <br /> <FieldArray name="people" component=FieldArrayComponent /> <button onClick=handleSubmit>submit form</button> </form> ; } ;
Add your custom validations
const isEmpty = value === undefined || value === null || value === ''; { if return 'Required'; return null;} { if !/^[a-zA-Z\s]+$/ return 'Alphabet'; return null;} { if !Number return 'Integer Only'; return null;}