Skip to content
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

v-model not working with input type hidden #372

Closed
gapipro opened this issue Jul 27, 2014 · 7 comments
Closed

v-model not working with input type hidden #372

gapipro opened this issue Jul 27, 2014 · 7 comments

Comments

@gapipro
Copy link

gapipro commented Jul 27, 2014

Don't know if I missed something but v-model doesn't seem to update it's value when value of hidden input changes.

Example: http://jsfiddle.net/zvjE6/

@gaydenko
Copy link

In the handler you need to change the model: this.type = 'pro';, but you are changing directly DOM element ('document.querySelector...`).

@gapipro
Copy link
Author

gapipro commented Jul 27, 2014

Yes. I made that on purpose, because I have an external library that changes hidden inputs values and I need that changes reflected to vue data model.

@gaydenko
Copy link

At such case (interaction between different worlds) I would use events sending (pub/sub). I guess it is conceptually correct: different worlds can not share data but can send messages to each other. But, I see, probably, that external library isn't events aware.

@yyx990803
Copy link
Member

Vue does not detect the changes when directly setting value on input elements, that is by design. If you know when your external lib has changed the input value, you can manually trigger a change event on your input element to notify Vue to sync the value back to the model.

@gapipro
Copy link
Author

gapipro commented Jul 29, 2014

Yes I solved this problem doing just that.

@SimonEast
Copy link

For others searching for this, the following jQuery code can be used to force Vue to update it's data once the value of the hidden field is changed (generally from some other external plugin or library)...

var input = $(#myHiddenInput');
input.val('Set new value');
input.trigger('change');

@vad11
Copy link

vad11 commented Jul 17, 2017

Please see #6135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants