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

#12 Do not validate an previous step

This commit is contained in:
cristijora
2017-06-07 22:59:36 +03:00
parent a67fc7bc93
commit 45306e301d
3 changed files with 9 additions and 8 deletions
+4 -4
View File
@@ -9,7 +9,7 @@
@on-loading="setLoading" @on-loading="setLoading"
@on-error="setError" @on-error="setError"
class="card" ref="wizard"> class="card" ref="wizard">
<tab-content title="1" icon="ti-settings"> <tab-content title="1" icon="ti-settings" :before-change="validateAsync">
First tab First tab
</tab-content> </tab-content>
<tab-content title="2" icon="ti-settings" :before-change="validateAsync"> <tab-content title="2" icon="ti-settings" :before-change="validateAsync">
@@ -52,13 +52,13 @@
//simulating an error for the first time and a success for the second time //simulating an error for the first time and a success for the second time
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
if (this.count < 1) { if (this.count % 2 === 0) {
this.count ++
reject('Some custom error') reject('Some custom error')
} else { } else {
resolve(true) resolve(true)
} }
}, 1000) this.count ++
}, 100)
}) })
}, },
validate () { validate () {
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -3
View File
@@ -13,7 +13,7 @@
</div> </div>
<ul class="wizard-nav wizard-nav-pills"> <ul class="wizard-nav wizard-nav-pills">
<li v-for="(tab, index) in tabs" :class="{active:tab.active}"> <li v-for="(tab, index) in tabs" :class="{active:tab.active}">
<a href="" @click.prevent="navigateToTab(index, false)"> <a href="" @click.prevent="navigateToTab(index)">
<div class="wizard-icon-circle" <div class="wizard-icon-circle"
:class="{checked:isChecked(index),square_shape:isStepSquare, tab_shape:isTabShape}" :class="{checked:isChecked(index),square_shape:isStepSquare, tab_shape:isTabShape}"
:style="[isChecked(index)? stepCheckedStyle : {}, tab.validationError ? errorStyle : {}]"> :style="[isChecked(index)? stepCheckedStyle : {}, tab.validationError ? errorStyle : {}]">
@@ -221,15 +221,16 @@
isChecked (index) { isChecked (index) {
return index <= this.maxStep return index <= this.maxStep
}, },
navigateToTab (index, validate = true) { navigateToTab (index) {
let validate = index > this.activeTabIndex
if (index <= this.maxStep) { if (index <= this.maxStep) {
let cb = () => { let cb = () => {
this.setValidationError(null)
this.changeTab(this.activeTabIndex, index) this.changeTab(this.activeTabIndex, index)
} }
if (validate) { if (validate) {
this.beforeTabChange(this.activeTabIndex, cb) this.beforeTabChange(this.activeTabIndex, cb)
} else { } else {
this.setValidationError(null)
cb() cb()
} }
} }