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

Only validate onblur of the field, and only if it's been edited #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TheJosh
Copy link

@TheJosh TheJosh commented Apr 16, 2021

The process of editing the field (the 'input' event) will activate the field for validation, and then the blur event does the actual validation.

This means that clicking into (or tabbing into) a field won't do anything if you then leave that field UNLESS if you actually enter
some content into the field; once some input has occurred, then the field is active, and from then onwards the blur events will trigger validation.

Not the most efficient code (especially for radio/checkbox) due to the double-events, but it works. Could be made better by removing the 'input' event handler upon first use and/or only adding the real event handler at activation point.

Testing:

  • Tested on Firefox/Linux and Chrome/Linux, with entering fields, inputting fields, chrome autofill, etc.
  • This has been running in PROD for several months now, on a site with >500k sessions/month.

The process of editing the field (the 'input' event) will activate
the field for validation, and then the blur event does the actual
validation.

This means that clicking into (or tabbing into) a field won't do
anything if you then leave that field UNLESS if you actually enter
some content into the field; once some input has occurred, then the
field is active, and from then onwards the blur events will trigger
validation.

Not the most efficient code (especially for radio/checkbox) due to
the double-events, but it works. Could be made better by removing
the 'input' event handler upon first use.

Tested on Firefox/Linux and Chrome/Linux, with entering fields,
inputting fields, chrome autofill, etc.
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.

1 participant