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
Async validator does not work after error #204
Comments
Since async validations are running on Example: import React, { Component } from 'react';
import { FormField } from 'react-form';
@FormField
class Text extends Component {
render() {
const {
fieldApi: {
getValue,
setValue,
setTouched,
getError,
getWarning,
getSuccess,
},
onChange,
onBlur,
...rest
} = this.props;
return (
<input
{...rest}
value={getValue() || ''}
onChange={async event => {
event.persist();
setValue(event.target.value);
await setTouched(); // this will trigger and wait for validations
// actual values after validation ended
console.log(getError(), getWarning(), getSuccess());
if (onChange) {
onChange(event);
}
}}
onBlur={event => {
setTouched();
if (onBlur) {
onBlur(event);
}
}}
/>
);
}
}
export default TextAsync; |
Hmm i dont think this is what we want. |
What do you propose to do? How can we get errors, warnings, successes in fields which have asynchronous validation? My solution does not break anything, just gives the opportunity to wait before validation is complete and get actual information about field. |
you know who is validating and when they are done based on the validating props. That being said maybe i could add callback that gets triggered when async validation is complete. |
I ran into this as well. @zalishchuk What did you mean when you said "Update: fixed that by adding synchronous validator." Does that mean that you just gave up on async and are using synchronous validation or that by adding synchronous validation it somehow forced the async to recheck after error? |
@cthurston Async validators are not running until error becomes |
Im still a little confused on the issue. is it that async validation is not running when a syncronous validation has already occurred on that field? |
If async validation produces an error there is no event that will clear it out. If you edit and blur the field again, it will not re-run the async validation because the error is still there. By adding a synchronous validation to the field it forces the error to be cleared out onChange. Therefore the async validation will run again. |
@cthurston In addition to your comment https://github.com/react-tools/react-form/blob/master/src/redux/actions.js#L147 |
A successful validation would clear it out though? would it not? |
If async validator produces an error once, field validation will not invoke. Check out my test repository and after try to add a simple synchronous validator for |
For example, in docs go to the async section and do the following.
|
@joepuzzo there is an |
Ok let me try this locally |
Ohh i see now.. ok i have meeting rn but ima look into this after because im starting to now think this is bug. |
Wooooowww i am stupid |
Somewhere in my code i was doing the following
It should have been
|
So i was merging errors and async errors internally.. they should only be merged for the user. |
Ok this is fixed in 2.14.3!!! |
Why async validator stops working after resolving first error?
https://github.com/zalishchuk/react-form-async-validators
Try to type anything into field, it run validator every time, but if you will type
error
(to resolve object with error) it will fail and die then, validator will never run again. Bug or feature and how can I disable this logic?Update: fixed that by adding synchronous validator.
Another question is how can I do things in custom text input
onChange
method after field finished validating. Something likewaitValidation
method infieldApi
to use it like this:The text was updated successfully, but these errors were encountered: