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

<select> doesn't select correct option after render #6903

Closed
fergusean opened this issue Oct 25, 2017 · 4 comments
Closed

<select> doesn't select correct option after render #6903

fergusean opened this issue Oct 25, 2017 · 4 comments
Labels

Comments

@fergusean
Copy link

fergusean commented Oct 25, 2017

Version

2.5.2

Reproduction link

https://jsfiddle.net/fergusean/a001nzw5/2/
https://jsfiddle.net/fergusean/a001nzw5/5/

Steps to reproduce

In the links, nothing. In your own instances, set a v-if on a select that also has a v-model (see examples).

What is expected?

The select should render, and the option whose value is == the value of the model bound to the select should be selected.

What is actually happening?

The first option in the select is active, until either a call to $forceUpdate, or another model is changed (click into the text field and type a letter). Then, suddenly, the correct value is selected in the dropdown.


This used to work in Vue 1. I upgraded and then discovered this. I'm working around it for now with a this.$nextTick(() => $this.forceUpdate());

I previous submitted this issue as #6882, however I believe @gebilaoxiong closed it prematurely. The provided "solution" changed the functionality and did not solve the actual issue.

@posva
Copy link
Member

posva commented Oct 25, 2017

It looks like there is a race condition happening.
As a work around you can also set a key on one of the select elements

@posva posva added the bug label Oct 25, 2017
@yyx990803
Copy link
Member

yyx990803 commented Oct 25, 2017

This is because the logic for updating the value when options change is inside componentUpdated and not called on bind, however in this case the presence of the directive is being toggled on the same select element.

@gebilaoxiong
Copy link
Member

gebilaoxiong commented Oct 25, 2017

@fergusean I'm sorry to close your issue too soon 😄

@yyx990803
Copy link
Member

closed via #6910

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

No branches or pull requests

4 participants