@@ -10,21 +10,6 @@ module.exports = {
1010 priority : 2000 ,
1111
1212 bind : function ( ) {
13-
14- // some helpful tips...
15- /* istanbul ignore if */
16- if (
17- process . env . NODE_ENV !== 'production' &&
18- this . el . tagName === 'OPTION' &&
19- this . el . parentNode && this . el . parentNode . __v_model
20- ) {
21- _ . warn (
22- 'Don\'t use v-for for v-model options; ' +
23- 'use the `options` param instead: ' +
24- 'http://vuejs.org/guide/forms.html#Dynamic_Select_Options'
25- )
26- }
27-
2813 // determine alias
2914 this . alias = this . arg
3015 // support "item in items" syntax
@@ -44,6 +29,17 @@ module.exports = {
4429 // uid as a cache identifier
4530 this . id = '__v-for__' + ( ++ uid )
4631
32+ // check if this is an option list,
33+ // so that we know if we need to update the <select>'s
34+ // v-model when the option list has changed.
35+ // because v-model has a lower priority than v-for,
36+ // the v-model is not bound here yet, so we have to
37+ // retrive it in the actual updateModel() function.
38+ var tag = this . el . tagName
39+ this . isOption =
40+ ( tag === 'OPTION' || tag === 'OPTGROUP' ) &&
41+ this . el . parentNode . tagName === 'SELECT'
42+
4743 // setup anchor nodes
4844 this . start = _ . createAnchor ( 'v-for-start' )
4945 this . end = _ . createAnchor ( 'v-for-end' )
@@ -76,9 +72,8 @@ module.exports = {
7672
7773 update : function ( data ) {
7874 this . diff ( data )
79- if ( this . ref ) {
80- this . updateRef ( )
81- }
75+ this . updateRef ( )
76+ this . updateModel ( )
8277 } ,
8378
8479 /**
@@ -235,6 +230,7 @@ module.exports = {
235230
236231 updateRef : function ( ) {
237232 var ref = this . ref
233+ if ( ! ref ) return
238234 var hash = ( this . _scope || this . vm ) . $
239235 var refs
240236 if ( ! this . converted ) {
@@ -252,6 +248,21 @@ module.exports = {
252248 }
253249 } ,
254250
251+ /**
252+ * For option lists, update the containing v-model on
253+ * parent <select>.
254+ */
255+
256+ updateModel : function ( ) {
257+ if ( this . isOption ) {
258+ var parent = this . start . parentNode
259+ var model = parent && parent . __v_model
260+ if ( model ) {
261+ model . forceUpdate ( )
262+ }
263+ }
264+ } ,
265+
255266 /**
256267 * Insert a fragment. Handles staggering.
257268 *
0 commit comments