Skip to content

Commit 2793ca2

Browse files
authored
Don't report dynamic types on inputs with v-model directive (#242)
1 parent 6b13226 commit 2793ca2

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

docs/rules/valid-v-model.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ This rule reports `v-model` directives in the following cases:
1111
- The directive does not have that attribute value. E.g. `<input v-model>`
1212
- The directive does not have the attribute value which is valid as LHS. E.g. `<input v-model="foo() + bar()">`
1313
- The directive is on unsupported elements. E.g. `<div v-model="foo"></div>`
14-
- The directive is on `<input>` elements which their types are dynamic. E.g. `<input :type="type" v-model="foo">`
1514
- The directive is on `<input>` elements which their types are `file`. E.g. `<input type="file" v-model="foo">`
1615
- The directive's reference is iteration variables. E.g. `<div v-for="x in list"><input type="file" v-model="x"></div>`
1716

lib/rules/valid-v-model.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,14 @@ function create (context) {
9393
data: { name }
9494
})
9595
}
96-
if (name === 'input') {
97-
if (utils.hasDirective(element, 'bind', 'type')) {
98-
context.report({
99-
node,
100-
loc: node.loc,
101-
message: "'v-model' directives don't support dynamic input types.",
102-
data: { name }
103-
})
104-
}
105-
if (utils.hasAttribute(element, 'type', 'file')) {
106-
context.report({
107-
node,
108-
loc: node.loc,
109-
message: "'v-model' directives don't support 'file' input type.",
110-
data: { name }
111-
})
112-
}
96+
97+
if (name === 'input' && utils.hasAttribute(element, 'type', 'file')) {
98+
context.report({
99+
node,
100+
loc: node.loc,
101+
message: "'v-model' directives don't support 'file' input type.",
102+
data: { name }
103+
})
113104
}
114105

115106
if (node.key.argument) {

tests/lib/rules/valid-v-model.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ tester.run('valid-v-model', rule, {
6666
{
6767
filename: 'test.vue',
6868
code: '<template><div><div v-for="x in list"><input v-model="x.foo"></div></div></template>'
69+
},
70+
{
71+
filename: 'test.vue',
72+
code: '<template><input :type="a" v-model="b"></template>'
73+
},
74+
{
75+
filename: 'test.vue',
76+
code: '<template><input v-bind:type="a" v-model="b"></template>'
6977
}
7078
],
7179
invalid: [
@@ -94,16 +102,6 @@ tester.run('valid-v-model', rule, {
94102
code: '<template><input v-model="a + b"></template>',
95103
errors: ["'v-model' directives require the attribute value which is valid as LHS."]
96104
},
97-
{
98-
filename: 'test.vue',
99-
code: '<template><input :type="a" v-model="b"></template>',
100-
errors: ["'v-model' directives don't support dynamic input types."]
101-
},
102-
{
103-
filename: 'test.vue',
104-
code: '<template><input v-bind:type="a" v-model="b"></template>',
105-
errors: ["'v-model' directives don't support dynamic input types."]
106-
},
107105
{
108106
filename: 'test.vue',
109107
code: '<template><input type="file" v-model="b"></template>',

0 commit comments

Comments
 (0)