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

Commit

Permalink
🐛 bug(validation): fix unregsiter error [ci skip]
Browse files Browse the repository at this point in the history
Closes #336
Closes #338
Closes #347
  • Loading branch information
kazupon committed Dec 12, 2016
1 parent 853b7b3 commit 39ba1ab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/components/validity-result-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export default function (Vue: GlobalAPI): Object {
this.resetResults(name)
})
},
validityCount (): Number {
return this._validityKeys.length
},
isRegistered (name: string): boolean {
return name in this._validities
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/validity/lifecycles.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function (Vue: GlobalAPI): Object {
if (validation) {
const { instance, name } = validation
const group = this.group
instance.unregister(this.field, this, { named: name, group })
instance.unregister(this.field, { named: name, group })
}

if (this._unwatchResultProp) {
Expand Down
23 changes: 16 additions & 7 deletions src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,29 @@ export default function (Vue: any): any {
const namedValidity: ?ValidityGroupComponent = named ? this._getValidityGroup('named', named) : null
if (named && group && namedValidity && groupValidity) {
groupValidity.unregister(field)
namedValidity.isRegistered(group) && namedValidity.unregister(group)
this._validityManager.isRegistered(named) && this._validityManager.unregister(named)
if (groupValidity.validityCount() === 0) {
namedValidity.isRegistered(group) && namedValidity.unregister(group)
this._unregisterValidityGroup('group', group)
}
if (namedValidity.validityCount() === 0) {
this._validityManager.isRegistered(named) && this._validityManager.unregister(named)
this._unregisterValidityGroup('named', named)
}
} else if (namedValidity) {
namedValidity.unregister(field)
this._validityManager.isRegistered(named) && this._validityManager.unregister(named)
if (namedValidity.validityCount() === 0) {
this._validityManager.isRegistered(named) && this._validityManager.unregister(named)
this._unregisterValidityGroup('named', named)
}
} else if (groupValidity) {
groupValidity.unregister(field)
this._validityManager.isRegistered(group) && this._validityManager.unregister(group)
if (groupValidity.validityCount() === 0) {
this._validityManager.isRegistered(group) && this._validityManager.unregister(group)
this._unregisterValidityGroup('group', group)
}
} else {
this._validityManager.unregister(field)
}

group && this._unregisterValidityGroup('group', group)
named && this._unregisterValidityGroup('named', named)
}

destroy (): void {
Expand Down

0 comments on commit 39ba1ab

Please sign in to comment.