do not advance multi step modal form unless valid

This commit is contained in:
dandds 2019-03-25 14:42:54 -04:00
parent e6fd32f612
commit 4987d24bef
2 changed files with 28 additions and 3 deletions

View File

@ -23,20 +23,40 @@ export default {
data: function() { data: function() {
return { return {
step: 0, step: 0,
fields: {},
} }
}, },
created: function() {
this.$root.$on('field-mount', this.handleFieldMount)
},
mounted: function() { mounted: function() {
return {} this.$root.$on('field-change', this.handleValidChange)
}, },
methods: { methods: {
next: function() { next: function() {
this.step += 1 if (this.isValid()) {
this.step += 1
}
}, },
goToStep: function(step) { goToStep: function(step) {
this.step = step if (this.isValid()) {
this.step = step
}
}, },
handleValidChange: function(event) {
const { name, valid } = event
this.fields[name] = valid
},
isValid: function() {
return !Object.values(this.fields).some(field => field === false)
},
handleFieldMount: function(event) {
const { name, optional } = event
this.fields[name] = optional
}
}, },
computed: {}, computed: {},

View File

@ -63,6 +63,11 @@ export default {
this.value = conformToMask(this.value, mask).conformedValue this.value = conformToMask(this.value, mask).conformedValue
} }
} }
},
created: function() {
this.$root.$emit('field-mount', { name: this.name, optional: this.optional })
}, },
methods: { methods: {