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

Add validateField() and use it in isFieldValid() #77

Merged
merged 7 commits into from
Oct 19, 2023
Merged

Add validateField() and use it in isFieldValid() #77

merged 7 commits into from
Oct 19, 2023

Conversation

dahlbyk
Copy link
Collaborator

@dahlbyk dahlbyk commented Oct 17, 2023

Expected isFieldValid() behavior is to check a single field, not the whole form. This is technically a breaking change, but the workaround is easy: call validateForm() (or isValid()) if you want to validate the whole form.

  • isValid() calls validateForm() unless prevalidate: false
  • isFieldValid() calls validateField() unless prevalidate: false

In both cases I tried to document that the synchronous return value isn't necessarily accurate if there's async validation.

Would welcome a demo from someone showing off how this can be used.

Comment on lines -970 to -974
let isDropdown = input.tagName.toLowerCase() === 'select';
let validateEvent = input.dataset.valEvent;
if (isDropdown) {
input.addEventListener('change', cb);
} else if (validateEvent) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I'm in the area I noticed the data-val-event override is being ignored for <select>. The attribute now takes precedence over the default change event.

@dahlbyk dahlbyk marked this pull request as ready for review October 18, 2023 04:01
Copy link
Owner

@haacked haacked left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@haacked haacked merged commit df3389c into main Oct 19, 2023
1 check passed
@haacked haacked deleted the gh76 branch October 19, 2023 08:58
@haacked
Copy link
Owner

haacked commented Oct 19, 2023

This is live on NPM! https://www.npmjs.com/package/aspnet-client-validation

@Maverik
Copy link

Maverik commented Oct 19, 2023

This may need a separate issue but I believe the change from this isn't reflected on README documentation yet and will likely cause some confusion around the pre-validation when used in updated release. Also it would be worth mentioning debounce functionality in that area for future users.

Thank you again for this work 🙌

This pull request was closed.
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

Successfully merging this pull request may close these issues.

isFieldValid not working as expected if prevalidate is false isFieldValid unexpected behaviours
3 participants