Vue 2 - input value is not updated in some cases
See original GitHub issueVue.js version
2.0.0.rc.7 and older
Reproduction Link
https://jsfiddle.net/Lonzpg7h/
Steps to reproduce
- Type one letter into input field - value won’t show up but console logs that event was fired
- Type more text - you will see now that value is updating correctly
- Now repeat step 1 but with removed
this.isDirty = value !== ''
or'is-dirty': this.isDirty
declaration - value shows up immediately
What is Expected?
I think input value should be visible on the first keystroke as well
What is actually happening?
In some case input value doesn’t show up until you enter text for the second time.
Any idea what’s going on here?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Input field's binded value does not update in Vue
I am expecting that binded input field value will change according respective variable - if I don't misunderstand the documentation, it's a ......
Read more >Input is not updating value when using created() option and v ...
I'm looping through config object inside created() hook since the Vue object doesn't seem to be available in my component at this time....
Read more >Adding a new todo form: Vue events, methods, and models
For installation, and to use some of the more advanced features of Vue (like Single File Components or render functions), you'll need a...
Read more >Updating unrelated Vue.js variable causing input values in ...
When a user types into one of your <input> elements you aren't storing that value anywhere. You've got a :value to poke the...
Read more >v-model not updating when data changes in edit form
If you are using the Vue dev tools extension for Chrome, you may want to investigate what's the updateId , updateJurisdictionName and updateJurisdictionStatus...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So what happens here is this:
isDirty
from true to falseisDirty
is used in the render functionthis.value
is still an empty string''
, the content of the input is reset.this.isDirty
is already trueThis only happens because you don’t $emit the event. If you do,
value
prop in the child…and everything would be fine. Your example broke the cycle, so to speak.
Edit: ah, Centaur beat me to it.
@sqal
In vue 2.0,
means if you don’t fire
input
event fromtextfield
, thevalue
prop oftextfield
will always remain the initial value oftext
which is''
.Since you never fire any
input
event, sovalue
prop never changes, so the only thing that can trigger the re-render oftextfield
is theisDirty
state.When you input a char for the first time, the char appears first, this is the native behavior of
input
tag. Then this input causes the change ofisDirty
fromfalse
totrue
, which in turn causes the re-render oftextfield
, notice that it’svalue
is still empty, so the content of the input gets cleared.For the subsequent char inputs, the native behavior of
input
still takes effect so you can see them as well. But this time,isDirty
remainstrue
, so no re-render occurred ontextfield
so the content is not cleared.If
this.isDirty = value !== ''
is removed, even the first re-render does not occur becauseisDirty
has not changed, so you can see what you have input immediately, that is just the consequence oftextfield
not being re-rendered.I modified your code into a template-based one to make things clearer.