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

Commit 312a000

Browse files
committed
🐛 bug(validate): fix multi element fragment bug
Fixes #243
1 parent a54f11f commit 312a000

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/directives/validate.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export default function (Vue) {
141141
this.field = camelize(this.arg ? this.arg : params.field)
142142

143143
this.validation = validator.manageValidation(
144-
this.field, model, this.vm, this.frag.node,
144+
this.field, model, this.vm, this.getElementFrom(this.frag),
145145
this._scope, filters, params.initial,
146146
this.isDetectBlur(params.detectBlur),
147147
this.isDetectChange(params.detectChange)
@@ -159,7 +159,7 @@ export default function (Vue) {
159159
listen () {
160160
const model = this.model
161161
const validation = this.validation
162-
const el = this.frag.node
162+
const el = this.getElementFrom(this.frag)
163163

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

186186
unlisten () {
187-
const el = this.frag.node
187+
const el = this.getElementFrom(this.frag)
188188

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

210210
teardownValidate () {
211211
if (this.validator && this.validation) {
212-
let el = this.frag.node
212+
const el = this.getElementFrom(this.frag)
213213

214214
this.params.group
215215
&& this.validator.removeGroupValidation(this.params.group, this.field)
@@ -289,6 +289,10 @@ export default function (Vue) {
289289
}
290290
}
291291
return ret
292+
},
293+
294+
getElementFrom (frag) {
295+
return frag.single ? frag.node : frag.node.nextSibling
292296
}
293297
})
294298
}

test/specs/issues.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,4 +452,40 @@ describe('github issues', () => {
452452
})
453453
})
454454
})
455+
456+
describe('#243', () => {
457+
beforeEach((done) => {
458+
el.innerHTML = `
459+
<validator name="validator1">
460+
<form novalidate>
461+
<input type="text" v-pickadate="'date'" v-validate:name="['required']">
462+
</form>
463+
</validator>
464+
`
465+
vm = new Vue({
466+
el,
467+
directives: {
468+
pickadate: {
469+
bind () {
470+
const elm = document.createElement('div')
471+
elm.innerHTML = '<p>hello world</p>'
472+
Vue.util.after(elm, this.el)
473+
}
474+
}
475+
}
476+
})
477+
vm.$nextTick(done)
478+
})
479+
480+
it('should be validated', (done) => {
481+
const field1 = vm.$el.querySelector('input')
482+
field1.value = 'hello'
483+
trigger(field1, 'input')
484+
trigger(field1, 'blur')
485+
vm.$nextTick(() => {
486+
assert(vm.$validator1.name.required === false)
487+
done()
488+
})
489+
})
490+
})
455491
})

0 commit comments

Comments
 (0)