Skip to content

Commit bea4d87

Browse files
committed
move input type=file warning to more proper place
1 parent 769c4dc commit bea4d87

File tree

1 file changed

+11
-10
lines changed
  • src/platforms/web/compiler/directives

1 file changed

+11
-10
lines changed

src/platforms/web/compiler/directives/model.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default function model (
1515
const modifiers = dir.modifiers
1616
const tag = el.tag
1717
const type = el.attrsMap.type
18+
1819
if (process.env.NODE_ENV !== 'production') {
1920
const dynamicType = el.attrsMap['v-bind:type'] || el.attrsMap[':type']
2021
if (tag === 'input' && dynamicType) {
@@ -23,7 +24,16 @@ export default function model (
2324
`v-model does not support dynamic input types. Use v-if branches instead.`
2425
)
2526
}
27+
// inputs with type="file" are read only and setting the input's
28+
// value will throw an error.
29+
if (tag === 'input' && type === 'file') {
30+
warn(
31+
`<${el.tag} v-model="${value}" type="file">:\n` +
32+
`File inputs are read only. Use a v-on:change listener instead.`
33+
)
34+
}
2635
}
36+
2737
if (tag === 'select') {
2838
genSelect(el, value, modifiers)
2939
} else if (tag === 'input' && type === 'checkbox') {
@@ -33,6 +43,7 @@ export default function model (
3343
} else {
3444
genDefaultModel(el, value, modifiers)
3545
}
46+
3647
// ensure runtime directive metadata
3748
return true
3849
}
@@ -136,16 +147,6 @@ function genDefaultModel (
136147
code = `if($event.target.composing)return;${code}`
137148
}
138149

139-
// inputs with type="file" are read only and setting the input's
140-
// value will throw an error.
141-
if (process.env.NODE_ENV !== 'production' &&
142-
type === 'file') {
143-
warn(
144-
`<${el.tag} v-model="${value}" type="file">:\n` +
145-
`File inputs are read only. Use a v-on:change listener instead.`
146-
)
147-
}
148-
149150
addProp(el, 'value', isNative ? `_s(${value})` : `(${value})`)
150151
addHandler(el, event, code, null, true)
151152
if (trim || number || type === 'number') {

0 commit comments

Comments
 (0)