Vee-validate: Input not re-validated on rule change when using dynamic rules

Created on 21 Jul 2017  Â·  4Comments  Â·  Source: logaretm/vee-validate

Versions:

  • VueJs: 2.4.2
  • Vee-Validate: 2.0.0-rc.7

Description:

When using dynamic rules as described in PR #202, the validation errors are cleared when the rules change, but the input is not actually re-validated.

Expectation:
When the rules change, the input could be invalid with respect to the new rules, so the input should be re-validated, and it should not only clear the errors as it does now.

Steps To Reproduce:

See: https://jsfiddle.net/3a618s8d/4/

  • In that JSFiddle, I have a field that should be numeric, but it is not required. In some conditions, that field actually is required, so I emulated this with the checkbox, which makes the field required when the checkbox is enabled.
  • When you check the checkbox, the field becomes required, but you do not get a validation error.
  • You need to manually cause an event in the input field, for example by doing a blur/unblur in order to have the validation run.
  • When you enter a string like "foo" in the input field, you will get an error that it is invalid. When you then toggle the checkbox and the rules change, the validation errors are cleared so the error disappears. However, clearly the input is invalid, so if you again cause something like a blur/unblur then the error appears again.
  • In short, you can dynamically change the rules, which works, and changing the rules clears the existing errors, which makes sense, but it does not re-validate the input with the new rules.

As a side note, we use this validation setup to emulate a "Required If" rule like Laravel has.

✨ enhancement

Most helpful comment

Sadly it didn't make it in RC.8, now the validator re-validates the field when all the following is true:

  • The field has been initialized.
  • The field has been already validated before (by user input or whatever).

All 4 comments

Many thanks for the detailed description, I agree with validating after the rules change, I should be able to implement it with PR #616

Thanks so much!

Sadly it didn't make it in RC.8, now the validator re-validates the field when all the following is true:

  • The field has been initialized.
  • The field has been already validated before (by user input or whatever).

I can confirm that it works in master. Nice, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MeltedFreddo picture MeltedFreddo  Â·  3Comments

Hoagiex picture Hoagiex  Â·  3Comments

saintplay picture saintplay  Â·  3Comments

yyyuuu777 picture yyyuuu777  Â·  3Comments

jagasan picture jagasan  Â·  3Comments