File tree 2 files changed +12
-1
lines changed
src/platforms/web/compiler/directives
test/unit/features/directives
2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import config from 'core/config'
4
4
import { addHandler , addProp , getBindingAttr } from 'compiler/helpers'
5
5
import { genComponentModel , genAssignmentCode } from 'compiler/directives/model'
6
6
7
+ const ternaryTextInputRE = / ^ [ ^ ? ] { 1 , } \? \s * ( ' | " | ` ) (?: t e x t | n u m b e r | p a s s w o r d | s e a r c h | e m a i l | t e l | u r l ) \1\s * : \s * ( ' | " | ` ) (?: t e x t | n u m b e r | p a s s w o r d | s e a r c h | e m a i l | t e l | u r l ) \2\s * $ /
7
8
let warn
8
9
9
10
// in some cases, the event used has to be determined at runtime
@@ -24,7 +25,7 @@ export default function model (
24
25
25
26
if ( process . env . NODE_ENV !== 'production' ) {
26
27
const dynamicType = el . attrsMap [ 'v-bind:type' ] || el . attrsMap [ ':type' ]
27
- if ( tag === 'input' && dynamicType ) {
28
+ if ( tag === 'input' && dynamicType && ! ternaryTextInputRE . test ( dynamicType ) ) {
28
29
warn (
29
30
`<input :type="${ dynamicType } " v-model="${ value } ">:\n` +
30
31
`v-model does not support dynamic input types. Use v-if branches instead.`
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
2
3
3
describe ( 'Directive v-model dynamic input type' , ( ) => {
4
+ it ( 'should not warn if supported ternary' , function ( ) {
5
+ new Vue ( {
6
+ data : {
7
+ type : 'text' ,
8
+ text : 'hi'
9
+ } ,
10
+ template : `<input :type="type ? 'text' : 'password'" v-model="text">`
11
+ } ) . $mount ( )
12
+ expect ( `v-model does not support dynamic input types` ) . not . toHaveBeenWarned ( )
13
+ } )
4
14
it ( 'should warn' , function ( ) {
5
15
new Vue ( {
6
16
data : {
You can’t perform that action at this time.
0 commit comments