-
Notifications
You must be signed in to change notification settings - Fork 12
Add `@validateOn="input", rename "blur" to "focusout" #31
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
Conversation
|
Release questions:
|
not yet -- I've opened this: #30 #30 has all the context for how to start releases if we want to publish to npm
as we are all maintainers, yes (again, if we're releasing). However, #30 is a blocker for doing any changeset / release stuff |
* This mimics the behavior of a user typing data into an input without yet focusing out of it. Browsers will only trigger a `change` event when focusing | ||
* out of the element, not while typing! | ||
* | ||
* `fillIn` will basically simulate entering the data *and* kinda focusing out (as it triggers `change`, however not `focusout`, which is impossible to achieve as a real user), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😮 I did NOT know this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, had to confirm this for myself by looking up their source.
I should probably create an issue. I guess we cannot change the existing behaviour of fillIn
, as that would break every app. But maybe we can upstream some additional helpers that cover the different real-world use cases better...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed this: emberjs/ember-test-helpers#1336
import { find, triggerEvent } from '@ember/test-helpers'; | ||
|
||
/** | ||
* Fill the provided text into the `value` property of the selected form element, similar to `fillIn`, but *without* implicitly triggering a `change` event. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10/10 would read again
assert | ||
.dom('[data-test-first-name-errors]') | ||
.doesNotExist( | ||
'validation errors are not rendered before validation happens on change' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: on change
-> on input
. Since this test is now testing for input
not change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ya, thanks! A lot of boilerplate in those tests, that I just copy-pased from the change
tests. Fixed that!
test-app/tests/integration/components/headless-form-validation-test.gts
Outdated
Show resolved
Hide resolved
.dom('[data-test-first-name-errors]') | ||
.exists( | ||
{ count: 1 }, | ||
'validation errors appear on focusout when validation fails' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: on focusout
-> on input
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to test that there are no errors on the last name field (by accident)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do, just a few lines below!
'validation errors are not rendered before initial validation happens before form is filled in' | ||
); | ||
|
||
await fillIn('[data-test-first-name]', 'Foo'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want input
here or fillIn
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @simonihmig is doing something similar here as the above tests - ensuring fillIn
doesn't cause errors to render, but below on line 1976 where he's using input
it does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it doesn't matter in this case too because the revalidate doesn't start until after submit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it doesn't matter here. And fillIn
is basically doing more as explained elsewhere (triggering input
and change
events), so when even fillIn
does not make errors show up, then input
would neither.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look great to me! Looks like a lingering @validateOn="blur"
which is causing CI to be red
error TS2322: Type '"blur"' is not assignable to type 'ValidateOn | undefined'.
* This mimics the behavior of a user typing data into an input without yet focusing out of it. Browsers will only trigger a `change` event when focusing | ||
* out of the element, not while typing! | ||
* | ||
* `fillIn` will basically simulate entering the data *and* kinda focusing out (as it triggers `change`, however not `focusout`, which is impossible to achieve as a real user), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
'validation errors are not rendered before initial validation happens before form is filled in' | ||
); | ||
|
||
await fillIn('[data-test-first-name]', 'Foo'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @simonihmig is doing something similar here as the above tests - ensuring fillIn
doesn't cause errors to render, but below on line 1976 where he's using input
it does
67e9fef
to
b099152
Compare
Right, thank you! Fixed that. Good to see that Glint is actually working 🙂 |
When playing with validations in a real demo rather than just looking for tests to become green, I realised that the behaviour we likely want for revalidation is not given when using
@revalidationOn="change"
. We want to have revalidation happen as soon as you type (into an invalid field) and it turns valid, without having to focus out of the input (which would effectively be@revalidationOn="blur"
). Butchange
does not trigger right while typing for inputs (normal texts inputs, checkboxes, radios and select boxes this is different though), only when focussing out ("committing"). (seechange
event).So this introduces another option
@revalidationOn="input"
, listening for theinput
event:The PR also takes this as a opportunity to rename
@(re)validationOn="blur"
to@(re)validationOn="focusout"
, as this is the event we are actually listening to, and having one value for the public API and another for the internal implementation did not really serve a meaningful purpose (other than maybeblur
being a bit more common), but could likely cause confusion.