Skip to content
This repository has been archived by the owner on Dec 25, 2017. It is now read-only.

Commit

Permalink
🐛 bug(validate): fix multi element fragment bug
Browse files Browse the repository at this point in the history
Fixes #243
  • Loading branch information
kazupon committed May 28, 2016
1 parent a54f11f commit 312a000
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/directives/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default function (Vue) {
this.field = camelize(this.arg ? this.arg : params.field)

this.validation = validator.manageValidation(
this.field, model, this.vm, this.frag.node,
this.field, model, this.vm, this.getElementFrom(this.frag),
this._scope, filters, params.initial,
this.isDetectBlur(params.detectBlur),
this.isDetectChange(params.detectChange)
Expand All @@ -159,7 +159,7 @@ export default function (Vue) {
listen () {
const model = this.model
const validation = this.validation
const el = this.frag.node
const el = this.getElementFrom(this.frag)

this.onBlur = bind(validation.listener, validation)
on(el, 'blur', this.onBlur)
Expand All @@ -184,7 +184,7 @@ export default function (Vue) {
},

unlisten () {
const el = this.frag.node
const el = this.getElementFrom(this.frag)

if (this.onInput) {
off(el, 'input', this.onInput)
Expand All @@ -209,7 +209,7 @@ export default function (Vue) {

teardownValidate () {
if (this.validator && this.validation) {
let el = this.frag.node
const el = this.getElementFrom(this.frag)

this.params.group
&& this.validator.removeGroupValidation(this.params.group, this.field)
Expand Down Expand Up @@ -289,6 +289,10 @@ export default function (Vue) {
}
}
return ret
},

getElementFrom (frag) {
return frag.single ? frag.node : frag.node.nextSibling
}
})
}
36 changes: 36 additions & 0 deletions test/specs/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,40 @@ describe('github issues', () => {
})
})
})

describe('#243', () => {
beforeEach((done) => {
el.innerHTML = `
<validator name="validator1">
<form novalidate>
<input type="text" v-pickadate="'date'" v-validate:name="['required']">
</form>
</validator>
`
vm = new Vue({
el,
directives: {
pickadate: {
bind () {
const elm = document.createElement('div')
elm.innerHTML = '<p>hello world</p>'
Vue.util.after(elm, this.el)
}
}
}
})
vm.$nextTick(done)
})

it('should be validated', (done) => {
const field1 = vm.$el.querySelector('input')
field1.value = 'hello'
trigger(field1, 'input')
trigger(field1, 'blur')
vm.$nextTick(() => {
assert(vm.$validator1.name.required === false)
done()
})
})
})
})

0 comments on commit 312a000

Please sign in to comment.