mirror of
https://github.com/tenrok/vue-form-wizard.git
synced 2026-06-22 20:50:33 +03:00
Watch route changes (browser back and forward)
This commit is contained in:
+2
-3
@@ -1,18 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<form-wizard @on-complete="onComplete"
|
<form-wizard @on-complete="onComplete"
|
||||||
shape="circle"
|
shape="square"
|
||||||
color="gray"
|
color="gray"
|
||||||
@on-loading="setLoading"
|
@on-loading="setLoading"
|
||||||
@on-error="setError"
|
@on-error="setError"
|
||||||
class="card" ref="wizard">
|
class="card" ref="wizard">
|
||||||
<tab-content title="Personal details"
|
<tab-content title="Personal details"
|
||||||
route="/first"
|
route="/first"
|
||||||
:before-change="validateAsync"
|
|
||||||
icon="ti-user">
|
icon="ti-user">
|
||||||
</tab-content>
|
</tab-content>
|
||||||
<tab-content title="Additional Info"
|
<tab-content title="Additional Info"
|
||||||
:before-change="validate"
|
:before-change="validateAsync"
|
||||||
route="/second"
|
route="/second"
|
||||||
icon="ti-settings">
|
icon="ti-settings">
|
||||||
</tab-content>
|
</tab-content>
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -49,7 +49,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<span @click="prevTab" v-if="displayPrevButton" class="wizard-footer-left">
|
<span @click="prevTab" v-if="displayPrevButton" class="wizard-footer-left">
|
||||||
<slot name="prev">
|
<slot name="prev">
|
||||||
<button type="button" class="wizard-btn btn-default wizard-btn-wd" :style="fillButtonStyle" :disabled="loading">
|
<button type="button" class="wizard-btn btn-default wizard-btn-wd" :style="fillButtonStyle"
|
||||||
|
:disabled="loading">
|
||||||
{{backButtonText}}
|
{{backButtonText}}
|
||||||
</button>
|
</button>
|
||||||
</slot>
|
</slot>
|
||||||
@@ -69,7 +70,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<span @click="nextTab" class="wizard-footer-right" v-if="!isLastStep">
|
<span @click="nextTab" class="wizard-footer-right" v-if="!isLastStep">
|
||||||
<slot name="next">
|
<slot name="next">
|
||||||
<button type="button" class="wizard-btn btn-fill wizard-btn-wd btn-next" :style="fillButtonStyle" :disabled="loading">
|
<button type="button" class="wizard-btn btn-fill wizard-btn-wd btn-next" :style="fillButtonStyle"
|
||||||
|
:disabled="loading">
|
||||||
{{nextButtonText}}
|
{{nextButtonText}}
|
||||||
</button>
|
</button>
|
||||||
</slot>
|
</slot>
|
||||||
@@ -102,6 +104,7 @@
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'Finish'
|
default: 'Finish'
|
||||||
},
|
},
|
||||||
|
validateOnBack: Boolean,
|
||||||
/***
|
/***
|
||||||
* Applies to text, border and circle
|
* Applies to text, border and circle
|
||||||
*/
|
*/
|
||||||
@@ -214,12 +217,16 @@
|
|||||||
isChecked (index) {
|
isChecked (index) {
|
||||||
return index <= this.maxStep
|
return index <= this.maxStep
|
||||||
},
|
},
|
||||||
navigateToTab (index) {
|
navigateToTab (index, validate = true) {
|
||||||
if (index <= this.maxStep) {
|
if (index <= this.maxStep) {
|
||||||
let cb = () => {
|
let cb = () => {
|
||||||
this.changeTab(this.activeTabIndex, index)
|
this.changeTab(this.activeTabIndex, index)
|
||||||
}
|
}
|
||||||
this.beforeTabChange(this.activeTabIndex, cb)
|
if (validate) {
|
||||||
|
this.beforeTabChange(this.activeTabIndex, cb)
|
||||||
|
} else {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setLoading (value) {
|
setLoading (value) {
|
||||||
@@ -319,13 +326,32 @@
|
|||||||
this.isLastStep = false
|
this.isLastStep = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.beforeTabChange(this.activeTabIndex, cb)
|
if (this.validateOnBack) {
|
||||||
|
this.beforeTabChange(this.activeTabIndex, cb)
|
||||||
|
} else {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
finish () {
|
finish () {
|
||||||
let cb = () => {
|
let cb = () => {
|
||||||
this.$emit('on-complete')
|
this.$emit('on-complete')
|
||||||
}
|
}
|
||||||
this.beforeTabChange(this.activeTabIndex, cb)
|
this.beforeTabChange(this.activeTabIndex, cb)
|
||||||
|
},
|
||||||
|
checkRouteChange (route) {
|
||||||
|
let matchingTabIndex = -1
|
||||||
|
let matchingTab = this.tabs.find((tab, index) => {
|
||||||
|
let match = tab.route === route
|
||||||
|
if (match) {
|
||||||
|
matchingTabIndex = index
|
||||||
|
}
|
||||||
|
return match
|
||||||
|
})
|
||||||
|
|
||||||
|
if (matchingTab && !matchingTab.active) {
|
||||||
|
const shouldValidate = matchingTabIndex > this.activeTabIndex
|
||||||
|
this.navigateToTab(matchingTabIndex, shouldValidate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
@@ -344,6 +370,11 @@
|
|||||||
} else {
|
} 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`)
|
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: {
|
||||||
|
'$route.path': function (newRoute) {
|
||||||
|
this.checkRouteChange(newRoute)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user