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

Commit

Permalink
🐛 bug(cleanup): fix cannot get validation result
Browse files Browse the repository at this point in the history
NOTE: ⚠️ not fixes validation result outside available yet

ref #236
  • Loading branch information
kazupon committed May 19, 2016
1 parent 1fbfc53 commit 33c71d1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
6 changes: 3 additions & 3 deletions test/specs/directives/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ describe('validator element directive', () => {
})

it('validator scope should not be assigned', () => {
assert(vm.$validator1 === null)
assert(vm.$validator1 === undefined)
})
})
})
Expand Down Expand Up @@ -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)
})
})
})
Expand Down
68 changes: 68 additions & 0 deletions test/specs/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,72 @@ describe('github issues', () => {
})
})
})

describe('#236', () => {
beforeEach((done) => {
el.innerHTML = `
<div v-if='show'>
<validator name="validator1">
<form novalidate>
<input type="text" v-model="name" v-validate:name="['required']">
<span v-if="!$validator1.valid">Name is required</span>
<pre>{{$validator1 | json}}</pre>
</form>
</validator>
</div>
<button @click="toogle">Toogle</button>{{ show }}
<pre>{{$validator1 | json}}</pre>
`
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()
})
})
})
})
})
})

0 comments on commit 33c71d1

Please sign in to comment.