-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Select value is not updated correctly when input handler triggers class change #6690
Comments
I printed https://jsfiddle.net/Linusborg/6dupwfpf/7/
... what am I missing? |
@LinusBorg The |
I took a look at what's happening here. Simpler fiddle: https://jsfiddle.net/ert66j1x/1/ I think the flow of events leading to the bug is:
As far as a solution, I think we want to make sure that the I can create a pull request but a little guidance would be helpful. NOTE: this is not replicable in firefox unless you put breakpoints in actuallySetSelected and in the listener callback that Vue adds for input element events. Unit test for this issue: it('should work on an element with an input binding', done => {
const vm = new Vue({
data: {
test1: '',
inputEvaluated: ''
},
template:
`<select v-model="test1" v-on:input="inputEvaluated = 'blarg'" v-bind:name="inputEvaluated">` +
'<option value="">test1 Please Select</option>' +
'<option value="alpha">Alpha</option>' +
'<option value="beta">Beta</option>' +
'</select>'
}).$mount()
document.body.appendChild(vm.$el)
vm.$el.children[1].selected = true
triggerEvent(vm.$el, 'input')
waitForUpdate(() => {
triggerEvent(vm.$el, 'change')
}).then(() => {
expect(vm.$el.value).toBe('alpha')
}).then(done)
}) |
Use the "input" event instead of "change" when listening for changes to the selection state since the "input" event will always fire before the "change" event. This avoids an issue where a user binds to the "input" event with "v-bind" and causes the component to update and set its model value back to the value of the select before it has received the new selection value. Fixes vuejs#6690
FYI IE and Edge do not trigger |
Version
2.4.4
Current chrome, safari
Reproduction link
https://jsfiddle.net/6dupwfpf/6/
Steps to reproduce
What is expected?
Value should be changed and "green" class applied.
What is actually happening?
"green" class is applied, but value stays unchanged.
Provided fiddle runs on version 2.4.0, but I tested it locally on 2.4.4 and it behaves exactly the same.
This report is linked to vuelidate/vuelidate#192
The text was updated successfully, but these errors were encountered: