-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting form's validation status onChange? #102
Comments
the validation status of any field isn't available |
Yes, this would be great otherwise I have to do yet another |
wrap the Inputs with your own component and add a valid className |
The functionality that I'm looking is form-wide, not field-specific. I want the submit button to be enabled and green the instant the entire form is valid. |
sure, makes sense. then just listen to |
Ahh okay. Thanks. |
Actually, I noticed that the errors begin to add up only as you interact or blur out of the fields or if you submit the form, so it's still not ideal. It would be nice if I could control the submit buttons view state just using something like I don't know if you want me to re-open this since it requires making Yup synchronous, which I doubt you want to do. |
its not possible to make yup sync but you control all the values needed to do that already. Put the initial validity in state, and change it as the form updates: componentWillMount() {
mySchema.isValid(initialValue)
. then(isValid => this.setState({ isValid }))
}
onError = (errors) => this.setState({
isValid: !Object.keys(errors).length
})
render() {
return (
<Form schema={mySchema} defaultValue={initialValue} onError={this.onError}>
{/* ... */}
<Form.Button disabled={!this.state.isValid} />
</Form>
} |
I just tried the code you showed me and it does not help my use-case because the Only the initial validation works properly. |
ok I'm not really sure i understand your use case then. |
Like i said, and demonstrated above, you can control the entire state of the form and do whatever you want. if you want to run validation for the entire form on each change, then do that in one of the callbacks. Generally tho i don't even think disabling a a submit button until the form is valid is a good idea. it makes it really easy to construct forms that are user hostile, e.g. the user has no idea what is required of them and no feedback from the inputs about what to do unless they blur through each and every input to trigger a warning. |
With the code you showed me, the submit button will be enabled when one field is valid, but the other fields are not valid. The user will get feedback on each field, it's just that there's no code-friendly way to see the validation status of the entire form during form |
Any progress or work around on this one? |
If you are looking to disable a submit button based on status for example, see sample code in #98 |
I'd also like to make this simpler, but it's ultimately fairly difficult to do given how state is managed in Form and Form.Buttons, need to be able to function outside (in a Form.Context) |
Is there a way to get the form's validation status during
onChange
? Right now the callbacks that you provide are error-centric, but there's no way to get valid-centric results.My use-case: I'd like to light something green when the form is valid and ready to be submitted.
The text was updated successfully, but these errors were encountered: