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
Stuck in invalid state after last validation constraint is removed while invalid #400
Labels
bug
Something isn't working
Comments
7 tasks
We should also check if our other components (which support validation) have the same issue. I can go though and check and report (or fix) them after fixing this. |
Haprog
added a commit
that referenced
this issue
Aug 8, 2019
…ed while invalid Fixes #400 Also fixed some typos in the tests and removed an unused iron-input reference that was not even a dependency.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The validation considers
required
,pattern
,maxlength
andminlength
. If any of those are set, then it setsinvalid
boolean based on the return value ofcheckValidity()
on the native<input>
. If none of those are set you can still manually setinvalid
totrue
orfalse
based on your own logic andvaadin-text-field
keeps the invalid state as it has been set.Currently the problem seems to be that when you only have one of those validation constraints set (e.g.
required
) and the field has been validated and become invalid (e.g. by just focusing and blurring a field that was required), and then you remove the constraint, it doesn't runcheckValidity()
on the native input anymore and it keeps theinvalid
state (as if it had been added manually). Basically the text field never automatically removesinvalid
state when there are no active validation constraints.This causes bad behaviour when e.g.
required
property has been bound to some value that updates based on other controls (e.g. a checkbox which toggles if some fields are required or not).I think the proper logic here would be to observe when any of
required
,pattern
,maxlength
orminlength
constraints is removed andinvalid == true
already, then setthis.invalid = this.inputElement.checkValidity();
When the field is
invalid
and any validation constraint (required
,pattern
,maxlength
,minlength
) is removed, validation should be run again andinvalid
state updated accordingly (even if there are no more active validation constraints). If it was the last/only validation constraint (e.g. changing a required field to not required)invalid
should basically be set tofalse
so that it doesn't get stuck as invalid.This was first reported at vaadin/vaadin-combo-box#830 and might affect also other components that internally use
vaadin-text-field
.Steps to reproduce
Put this on a page:
Now the only way to make it valid again is to either manually set
invalid = true
or make it required again and then change the value to something other than empty.The text was updated successfully, but these errors were encountered: