Skip to content

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

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

Closed
fergusean opened this issue Oct 23, 2017 · 2 comments
Closed

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

fergusean opened this issue Oct 23, 2017 · 2 comments

Comments

@fergusean
Copy link

fergusean commented Oct 23, 2017

Version

2.5.2

Reproduction link

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

Steps to reproduce

Nothing. Auto-fake AJAX data load.

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());

@gebilaoxiong
Copy link
Member

gebilaoxiong commented Oct 23, 2017

😄

https://jsfiddle.net/a001nzw5/4/

data: {
  options: [],
  myModel: null,
  myOtherModel: 'sample text'
}

@fergusean
Copy link
Author

That is not a solution. When options is null, the select isn't rendered. It is rendered once options becomes a non-null value, in this case, an array. Thus, the initial value of options should have no bearing.

Furthermore, I can reproduce this behavior by separating the loading indication from the options. See https://jsfiddle.net/fergusean/a001nzw5/5/. Same behavior.

It seems that it works as expected if the select is wrapped in a template. See https://jsfiddle.net/fergusean/a001nzw5/6/.

So, it looks like this is only a problem when the element shares a v-model and a v-if. Regardless, given that the magically switches to the correct value once any of the data in the Vue instance is mutated, I believe this to be unintended behavior, aka a bug.

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

2 participants