2
0
mirror of https://github.com/tenrok/vue-form-wizard.git synced 2026-06-22 10:40:33 +03:00

Final touches for async validations

This commit is contained in:
cristi
2017-04-24 22:38:26 +03:00
parent be0ea72f8b
commit e893461956
3 changed files with 18 additions and 16 deletions
+1
View File
@@ -16,6 +16,7 @@
My second tab content My second tab content
</tab-content> </tab-content>
<tab-content title="Last step" <tab-content title="Last step"
:before-change="validateAsync"
icon="ti-check"> icon="ti-check">
Yuhuuu! This seems pretty damn simple Yuhuuu! This seems pretty damn simple
</tab-content> </tab-content>
+1 -1
View File
File diff suppressed because one or more lines are too long
+16 -15
View File
@@ -207,29 +207,27 @@
this.loading = value this.loading = value
this.$emit('on-loading', value) this.$emit('on-loading', value)
}, },
validateTabChangePromise (promiseFn, callback) { validateBeforeChange (promiseFn, callback) {
// we have a promise // we have a promise
if (promiseFn.then && typeof promiseFn.then === 'function') { if (promiseFn.then && typeof promiseFn.then === 'function') {
this.setLoading(true) this.setLoading(true)
promiseFn.then((res) => { promiseFn.then((res) => {
this.setLoading(false) this.setLoading(false)
if (res === true) { let validationResult = res === true
callback() this.executeBeforeChange(validationResult, callback)
this.$emit('validated', true, this.activeTabIndex)
} else {
this.$emit('validated', false, this.activeTabIndex)
}
}).catch(() => { }).catch(() => {
this.setLoading(false) this.setLoading(false)
}) })
// we have a simple function // we have a simple function
} else { } else {
if (promiseFn) { let validationResult = promiseFn === true
this.$emit('validated', true, this.activeTabIndex) this.executeBeforeChange(validationResult, callback)
callback() }
} else { },
this.$emit('validated', false, this.activeTabIndex) executeBeforeChange (validationResult, callback) {
} this.$emit('on-validate', validationResult, this.activeTabIndex)
if (validationResult) {
callback()
} }
}, },
beforeTabChange (index, callback) { beforeTabChange (index, callback) {
@@ -239,7 +237,7 @@
let oldTab = this.tabs[index] let oldTab = this.tabs[index]
if (oldTab && oldTab.beforeChange !== undefined) { if (oldTab && oldTab.beforeChange !== undefined) {
let tabChangeRes = oldTab.beforeChange() let tabChangeRes = oldTab.beforeChange()
this.validateTabChangePromise(tabChangeRes, callback) this.validateBeforeChange(tabChangeRes, callback)
} else { } else {
callback() callback()
} }
@@ -291,7 +289,10 @@
this.beforeTabChange(this.activeTabIndex, cb) this.beforeTabChange(this.activeTabIndex, cb)
}, },
finish () { finish () {
this.$emit('on-complete') let cb = () => {
this.$emit('on-complete')
}
this.beforeTabChange(this.activeTabIndex, cb)
} }
}, },
mounted () { mounted () {