Vue: Model-binding with Select Drop-Down Syncs Disabled Selected Value

Created on 18 Nov 2015  ·  6Comments  ·  Source: vuejs/vue

Current the model binding will obtain the value of a disabled selected item (commonly used for default load state akin to placeholder in input fields). For example:

                    <select v-model="type">
                        <option disabled selected>Type of Change</option>
                        <option>Added</option>
                        <option>Fixed</option>
                        <option>Changed</option>
                        <option>Removed</option>
                    </select>

This will return "Type of Change" when querying this.type, unless the selection is changed. Would it not be more in-line with expectations to not get values of disabled items, even if they are selected?

feature request

Most helpful comment

Took me a while to figure this out, but here's a simple little trick to make this work: https://jsfiddle.net/83q5d713/2/

All 6 comments

Please use the forum for general queries. forum.vuejs.org
I would say that is expected behavior, it's disabled but what if you still want the value?

Hi @mat-moo, thanks for your feedback. The reason I thought it is unexpected, is because if you submit the form normally, the post data will not contain the disabled selected value.
I can work around it easily enough, that's not the issue. :)

I wonder why have no validator in the form.Submit a form that doesn‘t validate really okay?

Oh, I do have validation on the form, just not in the example here. :) If you think this isn't an issue, please feel free to close. It just didn't match up with my initial expectations, so I thought I would bring it up. :)

If you access the raw value of that select element, you will also get "Type of Change". I think it makes sense to keep current behavior.

Took me a while to figure this out, but here's a simple little trick to make this work: https://jsfiddle.net/83q5d713/2/

Was this page helpful?
0 / 5 - 0 ratings