File tree 2 files changed +23
-0
lines changed
src/platforms/web/compiler/directives
test/unit/features/directives
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,15 @@ export default function model (
15
15
const modifiers = dir . modifiers
16
16
const tag = el . tag
17
17
const type = el . attrsMap . type
18
+ if ( process . env . NODE_ENV !== 'production' ) {
19
+ const dynamicType = el . attrsMap [ 'v-bind:type' ] || el . attrsMap [ ':type' ]
20
+ if ( tag === 'input' && dynamicType ) {
21
+ warn (
22
+ `<input :type="${ dynamicType } " v-model="${ value } ">:\n` +
23
+ `v-model does not support dynamic input types. Use v-if branches instead.`
24
+ )
25
+ }
26
+ }
18
27
if ( tag === 'select' ) {
19
28
return genSelect ( el , value )
20
29
} else if ( tag === 'input' && type === 'checkbox' ) {
Original file line number Diff line number Diff line change
1
+ import Vue from 'vue'
2
+
3
+ describe ( 'Directive v-model dynamic input type' , ( ) => {
4
+ it ( 'should warn' , function ( ) {
5
+ new Vue ( {
6
+ data : {
7
+ type : 'text' ,
8
+ text : 'hi'
9
+ } ,
10
+ template : `<input :type="type" v-model="text">`
11
+ } ) . $mount ( )
12
+ expect ( `v-model does not support dynamic input types` ) . toHaveBeenWarned ( )
13
+ } )
14
+ } )
You can’t perform that action at this time.
0 commit comments