-
Notifications
You must be signed in to change notification settings - Fork 251
Validate fields together only after modification #683
Comments
Ah sorry, here's an updated link: http://codepen.io/davidkpiano/pen/yJwmEa/ |
Also, would this be an |
That's correct. I've made an example here. As you can see typing in the first field shows the error almost immediately before a user gets the chance to fill in the second. If it was possible to get the value of the first field in the second field's validation method, I think this could be solved by moving the |
Any news here? Similar question: or how to create dependent rule one field from another. i.e.:
|
required: (val, vals) => vals.last_name && vals.last_name.length && (!val || !val.length) add whole form values to validation function? |
I would only want to show an error if all fields I am validating have been 'touched'. So I would need values and the dirty status for all fields in the set. I'm thinking maybe fieldset level validations could be a thing to maintain backwards compatibility of the existing validation API. |
Fieldset level validations are in progress, but you can also add form-level validations.
<Form model="user"
validators={{
'': { city_required: ({ city, last_name }) => last_name ? !!city : true }
}}
>
Feel free to implement your own validation. The touched status is available on the if (forms.user.city.touched && forms.user.last_name.touched) {
if (!isCityValid(user.city)) {
this.setState({ cityValid: false });
}
} As an enhancement, I'll consider passing the form metadata as the second param for validation. |
ok, but how to say to "Error" component - show message only this two fields are touched? |
|
@divined What does your store look like? You can |
founded, ty. One more question: Can't find action to update whole form. i.e. trigger all fields revalidating. try:
and
|
Please do that. It would make validation easier. |
The Codepen linked to in the README.md is 404'ing. I looked through the revision history and I can't seem to fork the old one either.
I had a quick question about only triggering error messages. If you have a
password
andpassword_confirmation
field usingshow={{touched: true, focus: false}}
triggers an error message after just entering/leaving the first password field. Is there a way to push that to just the confirmation for UX purposes? Not a good idea to annoy a user that the confirmation is invalid before they've reached the field.I've got the JS ready to drop into your Codepen once the Forks are enabled.
Great library btw. Thank you for your hard work!
The text was updated successfully, but these errors were encountered: