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

fix(model): allow arbitrary naems for type binding #6802

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/platforms/web/compiler/modules/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {
addRawAttr(branch0, 'type', 'checkbox')
processElement(branch0, options)
branch0.processed = true // prevent it from double-processed
branch0.if = `type==='checkbox'` + ifConditionExtra
branch0.if = `(${typeBinding})==='checkbox'` + ifConditionExtra
addIfCondition(branch0, {
exp: branch0.if,
block: branch0
Expand All @@ -47,7 +47,7 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {
addRawAttr(branch1, 'type', 'radio')
processElement(branch1, options)
addIfCondition(branch0, {
exp: `type==='radio'` + ifConditionExtra,
exp: `(${typeBinding})==='radio'` + ifConditionExtra,
block: branch1
})
// 3. other
Expand Down
16 changes: 10 additions & 6 deletions test/unit/features/directives/model-dynamic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ describe('Directive v-model dynamic input type', () => {
it('should work', done => {
const vm = new Vue({
data: {
type: null,
inputType: null,
test: 'b'
},
template: `<input :type="type" v-model="test">`
template: `<input :type="inputType" v-model="test">`
}).$mount()
document.body.appendChild(vm.$el)

// test text
assertInputWorks(vm).then(done)
assertInputWorks(vm, 'inputType').then(done)
})

it('with v-if', done => {
Expand Down Expand Up @@ -87,7 +87,11 @@ describe('Directive v-model dynamic input type', () => {
})
})

function assertInputWorks (vm, chain) {
function assertInputWorks (vm, type, chain) {
if (typeof type !== 'string') {
if (!chain) chain = type
type = 'type'
}
if (!chain) chain = waitForUpdate()
chain.then(() => {
expect(vm.$el.value).toBe('b')
Expand All @@ -99,7 +103,7 @@ function assertInputWorks (vm, chain) {
expect(vm.test).toBe('c')
}).then(() => {
// change it to password
vm.type = 'password'
vm[type] = 'password'
vm.test = 'b'
}).then(() => {
expect(vm.$el.type).toBe('password')
Expand All @@ -109,7 +113,7 @@ function assertInputWorks (vm, chain) {
expect(vm.test).toBe('c')
}).then(() => {
// change it to checkbox...
vm.type = 'checkbox'
vm[type] = 'checkbox'
}).then(() => {
expect(vm.$el.type).toBe('checkbox')
expect(vm.$el.checked).toBe(true)
Expand Down