Skip to content
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

Validation errors not disappearing #52

Open
Thorarin opened this issue Sep 3, 2020 · 1 comment
Open

Validation errors not disappearing #52

Thorarin opened this issue Sep 3, 2020 · 1 comment

Comments

@Thorarin
Copy link

Thorarin commented Sep 3, 2020

I'm seeing some unexpected behavior when I trigger validation on a button press:

onSave = async (event: React.MouseEvent<HTMLButtonElement>) => {
        event.preventDefault();

        // I need to add this call, otherwise all the validation messages from
        // the previous submission attempt stay, even though the offending
        // input fields are fixed.
        this.form.current.reset();

        await this.form.current.validateForm();
        if (!this.form.current.isValid()) {
            console.log('Form invalid');
            return;
        }

        // Continue processing...
}

The examples don't have this reset() call, so I'm wondering what could cause this type of behavior?
I can't think of anything "special" I did in my form that would cause this.

I'm using version 0.15.0.

@tkrotoff
Copy link
Owner

Difficult to help without a demo.

If you want to re-validate all fields, use validateFields().

validateForm() "validates only all non-dirty fields"

I guess you are using React classes. Follow this example: https://codepen.io/tkrotoff/pen/BRGdqL
You should have:

  • <input onChange={handleChange} /> with handleChange calling validateFields(target)
  • onSubmit={this.handleSubmit} with handleSubmit calling validateForm()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants