You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The componentUpdated function is called because the input handler updates the value of data.inputEvaluated, which reverts the selection back to the original value of the v-model binding, since vue hasn't received the change event yet
The change event fires and we loop over the select options which have been reset in step 3, so we don't update the vue instance to the correct value
As far as a solution, I think we want to make sure that the v-modelchange event is handled before any other user added event handlers. I was thinking we could do this in normalizeEvents but I think it's only possible to reorder handlers for the same event there.
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=>{constvm=newVue({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=truetriggerEvent(vm.$el,'input')waitForUpdate(()=>{triggerEvent(vm.$el,'change')}).then(()=>{expect(vm.$el.value).toBe('alpha')}).then(done)})
Activity
LinusBorg commentedon Sep 26, 2017
I printed
$data
into the document to see what changedhttps://jsfiddle.net/Linusborg/6dupwfpf/7/
test1
is correctly changed byv-model
to'alpha'
inputEvaluated
correctly switches totrue
green
class is correctly applied... what am I missing?
posva commentedon Sep 26, 2017
@LinusBorg The
data
changes but not the DOM (if we print it in apre
tag): https://jsfiddle.net/vkrjspxy/However, using a
change
event instead makes it work: https://jsfiddle.net/tec1gqv3/1chriscasola commentedon Oct 3, 2017
@LinusBorg @posva
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:
input
event fires (because ofv-on:input
)input
handler updates the value ofdata.inputEvaluated
, which reverts the selection back to the original value of thev-model
binding, since vue hasn't received thechange
event yetchange
event fires and we loop over the select options which have been reset in step 3, so we don't update the vue instance to the correct valueAs far as a solution, I think we want to make sure that the
v-model
change
event is handled before any other user added event handlers. I was thinking we could do this in normalizeEvents but I think it's only possible to reorder handlers for the same event there.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:
fix(v-model): update model correctly when input event is bound
yyx990803 commentedon Oct 5, 2017
FYI IE and Edge do not trigger
input
on<select>
elements, so you should probably usechange
instead anyway...fix: use MessageChannel for nextTick
fix: use MessageChannel for nextTick
fix: use MessageChannel for nextTick