Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test($compile): #7048 warn if both v-model and v-bind:value used on same element #7056

Merged
merged 4 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,15 @@ function makeAttrsMap (attrs: Array<Object>): Object {
}
map[attrs[i].name] = attrs[i].value
}
if (
process.env.NODE_ENV !== 'production' &&
map['v-model'] &&
(map['v-bind:value'] || map[':value']) &&
(!map['type'] || map['type'] === 'text')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning should apply to anything that is not:

  • type=checkbox
  • type=radio
  • select

) {
var vBind = map['v-bind:value'] ? 'v-bind:value' : ':value'
warn('v-model and ' + vBind + ' used on the same text input')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could definitely use a more detailed message here - something like "v-bind:value conflicts with v-model on the same element because the latter already expands to a value binding internally"

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check looks good now - but I'm not sure if makeAttrsMap is the best place to do this check. Let's place it here since this warning is about v-model.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it's now been moved

return map
}

Expand Down
20 changes: 20 additions & 0 deletions test/unit/features/directives/model-text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@ describe('Directive v-model text', () => {
expect('You are binding v-model directly to a v-for iteration alias').toHaveBeenWarned()
})

it('warn if both v-model and v-bind:value are used on the same text input', () => {
new Vue({
data: {
test: 'foo'
},
template: '<input type="text" v-model="test" v-bind:value="test"/>'
}).$mount()
expect('v-model and v-bind:value used on the same text input').toHaveBeenWarned()
})

it('warn if both v-model and :value are used on the same text input', () => {
new Vue({
data: {
test: 'foo'
},
template: '<input type="text" v-model="test" :value="test"/>'
}).$mount()
expect('v-model and :value used on the same text input').toHaveBeenWarned()
})

if (!isAndroid) {
it('does not trigger extra input events with single compositionend', () => {
const spy = jasmine.createSpy()
Expand Down