File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
src/platforms/web/compiler/directives
test/unit/features/directives Expand file tree Collapse file tree 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'
44import { addHandler , addProp , getBindingAttr } from 'compiler/helpers'
55import { genComponentModel , genAssignmentCode } from 'compiler/directives/model'
66
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 * $ /
78let warn
89
910// in some cases, the event used has to be determined at runtime
@@ -24,7 +25,7 @@ export default function model (
2425
2526 if ( process . env . NODE_ENV !== 'production' ) {
2627 const dynamicType = el . attrsMap [ 'v-bind:type' ] || el . attrsMap [ ':type' ]
27- if ( tag === 'input' && dynamicType ) {
28+ if ( tag === 'input' && dynamicType && ! ternaryTextInputRE . test ( dynamicType ) ) {
2829 warn (
2930 `<input :type="${ dynamicType } " v-model="${ value } ">:\n` +
3031 `v-model does not support dynamic input types. Use v-if branches instead.`
Original file line number Diff line number Diff line change 11import Vue from 'vue'
22
33describe ( '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+ } )
414 it ( 'should warn' , function ( ) {
515 new Vue ( {
616 data : {
You can’t perform that action at this time.
0 commit comments