From f35f7e35cd48efc21e759752058c07a1ff32cfb6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 8 Oct 2016 14:15:05 -0400 Subject: [PATCH] add v-model dynamic type warning --- src/platforms/web/compiler/directives/model.js | 9 +++++++++ .../unit/features/directives/model-dynamic.spec.js | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/unit/features/directives/model-dynamic.spec.js diff --git a/src/platforms/web/compiler/directives/model.js b/src/platforms/web/compiler/directives/model.js index 2c867887..a59752e6 100644 --- a/src/platforms/web/compiler/directives/model.js +++ b/src/platforms/web/compiler/directives/model.js @@ -15,6 +15,15 @@ export default function model ( const modifiers = dir.modifiers const tag = el.tag const type = el.attrsMap.type + if (process.env.NODE_ENV !== 'production') { + const dynamicType = el.attrsMap['v-bind:type'] || el.attrsMap[':type'] + if (tag === 'input' && dynamicType) { + warn( + `:\n` + + `v-model does not support dynamic input types. Use v-if branches instead.` + ) + } + } if (tag === 'select') { return genSelect(el, value) } else if (tag === 'input' && type === 'checkbox') { diff --git a/test/unit/features/directives/model-dynamic.spec.js b/test/unit/features/directives/model-dynamic.spec.js new file mode 100644 index 00000000..87a4cb5c --- /dev/null +++ b/test/unit/features/directives/model-dynamic.spec.js @@ -0,0 +1,14 @@ +import Vue from 'vue' + +describe('Directive v-model dynamic input type', () => { + it('should warn', function () { + new Vue({ + data: { + type: 'text', + text: 'hi' + }, + template: `` + }).$mount() + expect(`v-model does not support dynamic input types`).toHaveBeenWarned() + }) +})