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

Internet Explorer dynamically added select elements display first option by default #2983

Closed
fergaldoyle opened this issue May 31, 2016 · 1 comment

Comments

@fergaldoyle
Copy link
Contributor

fergaldoyle commented May 31, 2016

http://codepen.io/anon/pen/gMbPrj

Visit the above page in IE11 and you'll see two select boxes, both with empty initial values which is what we expect.

Click the show button to display two more select boxes (identical to the first two, but inside a v-if) and they will have initial values of AAA, which is bad.

Also the select element which is inside the test component gets an initial value of AAA. It seems that the select element needs to be in the DOM during page load for it work as expected. Anything added dynamically (inside a v-if or through component templates) gets an initial value which takes it out of sync of the underlying model.

I believe this happens only on Windows 8 & 10 (the select element is different from older versions of Windows).

@fergaldoyle fergaldoyle changed the title Internet Explorer select element inside v-if displays first option by default Internet Explorer dynamically added select elements display first option by default May 31, 2016
@fergaldoyle
Copy link
Contributor Author

Doing some local debugging, I found changing this line:

this.vm.$on('hook:attached', this.forceUpdate)

to:
this.vm.$nextTick(this.forceUpdate);

Solved the issue. From what I can see it doesn't break existing functionality.

A separate but related issue (in IE) is when a select element is moved (either the element itself or when it's a descendant of a moved element) within the DOM, even with the above code change, it will reset and present the same issue as above (displaying the first option instead of a blank).
e.g:

<div id="move">
   <label> Test
       <select v-model="selected">...</select>
   </label>
</div>
<div id="dest"></div>
document.querySelector('#dest').appendChild(document.querySelector('#move'));

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

1 participant