React-final-form: How to validate and set errors in array fields ?

Created on 3 Jan 2018  路  7Comments  路  Source: final-form/react-final-form

Any tips on how to Validate array form elements ? And how do I show error in each of Array element ?

e.g. from the example sandbox for arrays, if array element is added is it required or supposed to be an int.

Most helpful comment

@maciejmyslinski Could you please make an example for a form level validation? There is already an example for field level validation https://codesandbox.io/s/43x51p3q2w.

All 7 comments

The errors object has to correspond to the shape of the values object. e.g. If you have a field called addresses[2].street, the value for that field will be values.addresses[2].street and the error needs to be accessible from errors.addresses[2].street. Does that clear anything up? If not, provide a more concrete example and I'll try to help further.

@erikras would it be possible to add validation/error for example for Field Arrays in README : https://codesandbox.io/s/kx8qv67nk5 ?

Just want a reference, I tried locally to add assertions I had to do a basically create an empty array and then push objects into it. Would love to see best practice.

@erikras ^^

would it be possible to add validation/error for example for Field Arrays in README

I plan to. Just haven't gotten around to it yet.

@erikras if you could please give me guidance on what kind of validation we'd like to demo (form/field level) I can give this one a shot 馃槑

@maciejmyslinski Could you please make an example for a form level validation? There is already an example for field level validation https://codesandbox.io/s/43x51p3q2w.

Any updates? Can someone make an example if it works already? I mean form-level array field validation

Was this page helpful?
0 / 5 - 0 ratings