Skip to content

Commit

Permalink
remove inline value warnings for checkbox/radio/select also (close #5112
Browse files Browse the repository at this point in the history
)
  • Loading branch information
yyx990803 committed Mar 8, 2017
1 parent 2e1e809 commit c619b8d
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 71 deletions.
34 changes: 0 additions & 34 deletions src/platforms/web/compiler/directives/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ function genCheckboxModel (
value: string,
modifiers: ?ASTModifiers
) {
if (process.env.NODE_ENV !== 'production' &&
el.attrsMap.checked != null) {
warn(
`<${el.tag} v-model="${value}" checked>:\n` +
`inline checked attributes will be ignored when using v-model. ` +
'Declare initial values in the component\'s data option instead.'
)
}
const number = modifiers && modifiers.number
const valueBinding = getBindingAttr(el, 'value') || 'null'
const trueValueBinding = getBindingAttr(el, 'true-value') || 'true'
Expand Down Expand Up @@ -109,14 +101,6 @@ function genRadioModel (
value: string,
modifiers: ?ASTModifiers
) {
if (process.env.NODE_ENV !== 'production' &&
el.attrsMap.checked != null) {
warn(
`<${el.tag} v-model="${value}" checked>:\n` +
`inline checked attributes will be ignored when using v-model. ` +
'Declare initial values in the component\'s data option instead.'
)
}
const number = modifiers && modifiers.number
let valueBinding = getBindingAttr(el, 'value') || 'null'
valueBinding = number ? `_n(${valueBinding})` : valueBinding
Expand All @@ -129,10 +113,6 @@ function genSelect (
value: string,
modifiers: ?ASTModifiers
) {
if (process.env.NODE_ENV !== 'production') {
el.children.some(checkOptionWarning)
}

const number = modifiers && modifiers.number
const selectedVal = `Array.prototype.filter` +
`.call($event.target.options,function(o){return o.selected})` +
Expand All @@ -145,20 +125,6 @@ function genSelect (
addHandler(el, 'change', code, null, true)
}

function checkOptionWarning (option: any): boolean {
if (option.type === 1 &&
option.tag === 'option' &&
option.attrsMap.selected != null) {
warn(
`<select v-model="${option.parent.attrsMap['v-model']}">:\n` +
'inline selected attributes on <option> will be ignored when using v-model. ' +
'Declare initial values in the component\'s data option instead.'
)
return true
}
return false
}

function genDefaultModel (
el: ASTElement,
value: string,
Expand Down
11 changes: 0 additions & 11 deletions test/unit/features/directives/model-checkbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,4 @@ describe('Directive v-model checkbox', () => {
expect(vm.$el.checked).toBe(true)
}).then(done)
})

it('warn inline checked', () => {
const vm = new Vue({
template: `<input type="checkbox" v-model="test" checked>`,
data: {
test: false
}
}).$mount()
expect(vm.$el.checked).toBe(false)
expect('inline checked attributes will be ignored when using v-model').toHaveBeenWarned()
})
})
11 changes: 0 additions & 11 deletions test/unit/features/directives/model-radio.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,4 @@ describe('Directive v-model radio', () => {
expect(vm.$el.checked).toBe(false)
}).then(done)
})

it('warn inline checked', () => {
const vm = new Vue({
template: `<input v-model="test" type="radio" value="1" checked>`,
data: {
test: '2'
}
}).$mount()
expect(vm.$el.checked).toBe(false)
expect('inline checked attributes will be ignored when using v-model').toHaveBeenWarned()
})
})
15 changes: 0 additions & 15 deletions test/unit/features/directives/model-select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,6 @@ describe('Directive v-model select', () => {
}).then(done)
})

it('should warn inline selected', () => {
const vm = new Vue({
data: {
test: null
},
template:
'<select v-model="test">' +
'<option selected>a</option>' +
'</select>'
}).$mount()
expect(vm.$el.selectedIndex).toBe(-1)
expect('inline selected attributes on <option> will be ignored when using v-model')
.toHaveBeenWarned()
})

it('should warn multiple with non-Array value', done => {
new Vue({
data: {
Expand Down

0 comments on commit c619b8d

Please sign in to comment.