2
0
mirror of https://github.com/tenrok/vue-form-wizard.git synced 2026-06-07 03:02:24 +03:00

Move example to dev-example folder

Remove watcher from FormWizard component to avoid double beforeChange trigger
Code cleanup
This commit is contained in:
cristi
2017-04-23 22:45:19 +03:00
parent 7c39f53908
commit f2b6af4eee
9 changed files with 69 additions and 57 deletions
+11 -14
View File
@@ -213,8 +213,11 @@
this.setLoading(true)
promiseFn.then((res) => {
this.setLoading(false)
if (res) {
if (res === true) {
callback()
this.$emit('validated', true, this.activeTabIndex)
} else {
this.$emit('validated', false, this.activeTabIndex)
}
}).catch(() => {
this.setLoading(false)
@@ -222,7 +225,10 @@
// we have a simple function
} else {
if (promiseFn) {
this.$emit('validated', true, this.activeTabIndex)
callback()
} else {
this.$emit('validated', false, this.activeTabIndex)
}
}
},
@@ -242,11 +248,9 @@
let oldTab = this.tabs[oldIndex]
let newTab = this.tabs[newIndex]
if (oldTab) {
oldTab.show = false
oldTab.active = false
}
if (newTab) {
newTab.show = true
newTab.active = true
}
this.activeTabIndex = newIndex
@@ -280,7 +284,7 @@
prevTab () {
let cb = () => {
if (this.activeTabIndex > 0) {
this.activeTabIndex--
this.changeTab(this.activeTabIndex, this.activeTabIndex - 1)
this.isLastStep = false
}
}
@@ -292,25 +296,18 @@
},
mounted () {
this.tabs = this.$children.filter((comp) => comp.$options.name === 'tab-content')
if (this.tabs.length > 0) {
if (this.tabs.length > 0 && this.startIndex === 0) {
let firstTab = this.tabs[this.activeTabIndex]
firstTab.show = true
firstTab.active = true
}
if (this.startIndex < this.tabs.length) {
let tabToActivate = this.tabs[this.startIndex]
this.activeTabIndex = this.startIndex
tabToActivate.active = true
this.maxStep = this.startIndex
} else {
console.warn(`Prop startIndex set to ${this.startIndex} is greater than the number of tabs - ${this.tabs.length}. Make sure that the starting index is less than the number of tabs registered`)
}
},
watch: {
activeTabIndex: function (newVal, oldVal) {
let cb = () => {
this.changeTab(oldVal, newVal)
}
this.beforeTabChange(oldVal, cb)
}
}
}
</script>
+1 -2
View File
@@ -1,5 +1,5 @@
<template>
<div v-show="show" class="tab-container">
<div v-if="active" class="tab-container">
<slot>
</slot>
</div>
@@ -30,7 +30,6 @@
},
data () {
return {
show: false,
active: false
}
}