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
Form valid event issued when elements are invalid. #92
Comments
Hi Geoff, thank you for the feedback! I see the problem, but unfortunately that’s based on a misconception. The There is indeed a non-standard form-level event So, long story short, where does the I hope, this explanation makes some sense. I’m keeping the issue open for now, because that’s definitively something I should document better. (*) not for methods like |
Thanks for clearing that up @Boldewyn, I appreciate the detailed explanation. In order to do what I want would I be best just calling form.checkValidity() every time a form field changes and using the return value, or is there some internal registry or field inside the hyperform I could tap into? I know I could use my own eyes, but I'm hoping your knowledge could point me in the right direction to start :-) Cheers! |
Let’s see... No, there is no internal bookkeeping of the state of single input elements, but you could create that quickly yourself (ES6 needed, though):
If an element changes state, you can update the map, thanks to event bubbling, from the
And to check, if all elements are valid, you could do something like
The solution will become a bit more complicated, if you add/remove elements dynamically. For that case you could use a |
Thanks @Boldewyn / Manuel, couldn't have asked for a better head start on it! |
I'm trying to use Hyperform to detect when the form switches between an invalid and valid state so I can switch disabling of the submit button.
If I monitor the "valid" event on the form it keeps getting triggered even though elements within the form are still invalid.
If I run form.checkValidity() on startup each field will indicate an "invalid" event and checkValidity returns false. It seems calling "checkValidity" on the form won't trigger any event on the form (validate, invalid or valid).
I've got a test with three required text fields and a submit button. If I tab through the fields they each report "invalid" events, but nothing at the form level. Once I reach the submit button the form reports a "valid" event (when it should really be "invalid").
Test, if it helps, is at: https://codepen.io/GeoffCapper/pen/eYNQWYr
When I click submit the form issues a "validate" event, and each field in turn issues an "invalid" event followed by the form issuing an "invalid" event. Once all the fields have been checked the form then issues a "valid" event.
Are the form-level "valid"/"invalid" events broken, or are they for some other purpose than I'm thinking?
Thanks,
Geoff
The text was updated successfully, but these errors were encountered: