mirror of
https://github.com/tenrok/vue-form-wizard.git
synced 2026-06-22 09:20:32 +03:00
Final touches for async validations
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -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 () {
|
||||||
|
|||||||
Reference in New Issue
Block a user