Skip to content

Commit

Permalink
Inputs can be an array of objects instead of uids
Browse files Browse the repository at this point in the history
 - Validate runs through all inputs again instead of stopping at the first error
  • Loading branch information
KaelWD committed Sep 4, 2017
1 parent c713172 commit 9a5063b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/components/VForm/VForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,20 @@ export default {

if (inputs.length < this.inputs.length) {
// Something was removed, we don't want it in the errorBag any more
const newUids = inputs.map(i => i._uid)

const removed = this.inputs.filter(i => !newUids.includes(i))
const removed = this.inputs.filter(i => !inputs.includes(i))

for (const input of removed) {
this.$delete(this.errorBag, input)
this.$delete(this.errorBag, input._uid)
this.$delete(this.inputs, this.inputs.indexOf(input))
}
}

for (const child of inputs) {
if (this.inputs.includes(child._uid)) {
if (this.inputs.includes(child)) {
continue // We already know about this input
}

this.inputs.push(child._uid)
this.inputs.push(child)

// Only start watching inputs if we need to
child.$watch('shouldValidate', (val) => {
Expand All @@ -80,10 +78,10 @@ export default {
}
},
validate () {
return this.getInputs().every(i => i.validate(true))
return !this.inputs.filter(input => input.validate(true)).length
},
reset () {
this.getInputs().forEach((input) => input.reset())
this.inputs.forEach((input) => input.reset())
Object.keys(this.errorBag).forEach(key => this.$delete(this.errorBag, key))
}
},
Expand Down

0 comments on commit 9a5063b

Please sign in to comment.