diff --git a/src/validator.js b/src/validator.js index 48311f1..dc61d88 100644 --- a/src/validator.js +++ b/src/validator.js @@ -50,11 +50,16 @@ export default class Validator { disableReactive () { let vm = this._dir.vm - vm.$setValidationErrors = undefined - vm.$validate = undefined - vm.$validatorReset = undefined + vm.$setValidationErrors = null + delete vm['$setValidationErrors'] + vm.$validate = null + delete vm['$validate'] + vm.$validatorReset = null + delete vm['$validatorReset'] vm._validatorMaps[this.name] = null + delete vm._validatorMaps[this.name] vm[this.name] = null + delete vm[this.name] } registerEvents () { diff --git a/test/specs/directives/validator.js b/test/specs/directives/validator.js index 51e3b6f..a1b97ec 100644 --- a/test/specs/directives/validator.js +++ b/test/specs/directives/validator.js @@ -260,7 +260,7 @@ describe('validator element directive', () => { }) it('validator scope should not be assigned', () => { - assert(vm.$validator1 === null) + assert(vm.$validator1 === undefined) }) }) }) @@ -363,8 +363,8 @@ describe('validator element directive', () => { }) it('should not be assigned', () => { - assert(vm.$validator0 === null) - assert(vm.$validator1 === null) + assert(vm.$validator0 === undefined) + assert(vm.$validator1 === undefined) }) }) }) diff --git a/test/specs/issues.js b/test/specs/issues.js index 7f6f4d2..e4d8cb5 100644 --- a/test/specs/issues.js +++ b/test/specs/issues.js @@ -384,4 +384,72 @@ describe('github issues', () => { }) }) }) + + describe('#236', () => { + beforeEach((done) => { + el.innerHTML = ` +
+ +
+ + Name is required +
{{$validator1 | json}}
+
+
+
+ {{ show }} +
{{$validator1 | json}}
+ ` + vm = new Vue({ + el: el, + data: { + name: 'test', + show: true + }, + methods: { + toogle () { + if (this.$data.show) { + this.$data.show = false + } else { + this.show = true + } + } + } + }) + vm.$nextTick(done) + }) + + it('should be validated', (done) => { + assert(vm.validator1 !== null) + + let button = el.getElementsByTagName('button')[0] + let input = el.getElementsByTagName('input')[0] + input.value = '' + trigger(input, 'input') + trigger(input, 'blur') + trigger(button, 'click') + vm.$nextTick(() => { + assert(vm['$validator1'] === undefined) + assert(vm._validatorMaps['$validator1'] === undefined) + + trigger(button, 'click') + vm.$nextTick(() => { + assert(vm.$validator1 !== null) + assert(vm.$validator1.name.invalid === true) + assert(vm.$validator1.name.required) + + input = el.getElementsByTagName('input')[0] + input.value = 'test' + trigger(input, 'input') + trigger(input, 'blur') + vm.$nextTick(() => { + assert(vm.$validator1.name.invalid === false) + assert(vm.$validator1.name.required === false) + + done() + }) + }) + }) + }) + }) })