-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Bug] {{on}} modifier on input fired before bound value is updated #19222
Comments
I investigated a related issue in emberjs/ember-test-helpers#1128 (comment). The problem is that When you wrap your listener in |
@buschtoens hm, the bug is still present for me in your updated Twiddle. using |
Interesting! I'm using Firefox and there it works. You're using Chrome, I guess? There it's indeed not working.
This comes at a cost though: it's essentially calling I wanted to file a very closely related |
@buschtoens Yeah, I tried in Safari and Chrome. |
I've stumbled across this bug, while refactoring from the |
Any update on this bug? |
The bug relies on the super old two-way binding behavior, and I think we're wanting to encourage people to not use In this example, I don't think I was able to reproduce the problem. |
Dear @NullVoxPopuli, Thanks for the fast reply. Is a PR to https://guides.emberjs.com/release/components/built-in-components/ welcome to high-light this? |
absolutely! that'd be wonderful! |
🐞 Describe the Bug
When using the {{on}} modifier on an input the callback is fired before the bound value is updated.
From the documentation
<Input @id="input-name" @value={{this.name}} {{on "input" this.validateName}} />
In
validateName
I would assume I can validate the name by usingthis.name
but it doesn't have the correct value at this time.This differ from the "old" way of using an argument for the event:
<Input @id="input-name" @value={{this.name}} @input={{this.validateName}} />
This might be indented but it wasn't clear for me, especially coming from using the "old" way.
🔬 Minimal Reproduction
https://ember-twiddle.com/89e1a8168304360b322981218ee218ff
😕 Actual Behavior
When using the {{on}} modifier the bound value isn't updated before the modifier callback is run, which differs from the "old" way using an event argument.
Example:
If I have
<Input @value={{this.name}} {{on "input" this.validateName}} />
and I type "John Doe" in this input field,by the time
this.validateName
is calledthis.name
will have the value "John Do".Using the "old" way
<Input @value={{this.name}} @input={{this.validateName}} />
this.name
will have the value "John Doe".🤔 Expected Behavior
When using the bound value in the modifier callback I expect it to be the updated value. If this is intended maybe it should at least be clarified in the documentation?
Example:
If I have
<Input @value={{this.name}} {{on "input" this.validateName}} />
and I type "John Doe" in this input field.by the time
this.validateName
is called I expectthis.name
to have the value "John Doe".🌍 Environment
The text was updated successfully, but these errors were encountered: