Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit f369fde

Browse files
committed
Fix #28 Error to activate tab in destroyed hook
1 parent 9d7a019 commit f369fde

File tree

5 files changed

+140
-80
lines changed

5 files changed

+140
-80
lines changed

dev-example/App.vue

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,12 @@
11
<template>
22
<div>
3-
<button @click="tabs.shift()">Remove one at start</button>
4-
<button @click="tabs.push('testt')">Add at the end</button>
5-
<button @click="tabs.unshift('new start')">Add one at start</button>
6-
<form-wizard @on-complete="onComplete"
7-
:hide-buttons="false"
8-
shape="square"
9-
color="gray"
10-
@on-loading="setLoading"
11-
@on-error="setError"
12-
class="card" ref="wizard">
13-
<template slot="step" scope="props">
14-
<wizard-step :tab="props.tab"
15-
transition="fade"
16-
:key="props.tab.title"
17-
:index="props.index">
18-
</wizard-step>
19-
</template>
203

21-
<tab-content title="Personal details" icon="ti-user">
22-
My first tab
23-
</tab-content>
24-
<tab-content v-for="tab in tabs" :title="tab" :key="tab" icon="ti-settings">
25-
{{tab}}
26-
</tab-content>
27-
<div class="loader" v-if="loadingWizard"></div>
28-
<div v-if="error">
29-
{{error}}
30-
</div>
31-
</form-wizard>
4+
<router-view></router-view>
325
</div>
336
</template>
347

358
<script>
36-
import TabContent from "../src/components/TabContent";
37-
38-
export default {
39-
components: {TabContent},
40-
name: 'app',
41-
data () {
42-
return {
43-
loadingWizard: false,
44-
error: null,
45-
count: 0,
46-
tabs: ['test', 'test2', 'test3']
47-
}
48-
},
49-
methods: {
50-
onComplete () {
51-
alert('Yay!')
52-
},
53-
setLoading (value) {
54-
this.loadingWizard = value
55-
},
56-
setError (error) {
57-
this.error = error
58-
},
59-
validateAsync () {
60-
//simulating an error for the first time and a success for the second time
61-
return new Promise((resolve, reject) => {
62-
setTimeout(() => {
63-
if (this.count % 2 === 0) {
64-
reject('Some custom error')
65-
} else {
66-
resolve(true)
67-
}
68-
this.count++
69-
}, 100)
70-
})
71-
},
72-
validate () {
73-
return true
74-
}
75-
}
76-
}
9+
export default {}
7710
</script>
7811
<style>
7912
@import "loader.css";

dev-example/TestRoute.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>
3+
Test route
4+
<router-link to="/">Go to wizard</router-link>
5+
</div>
6+
</template>
7+
<script>
8+
export default {}
9+
</script>
10+
<style>
11+
</style>

dev-example/WizardRoute.vue

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<template>
2+
<div>
3+
<button @click="tabs.shift()">Remove one at start</button>
4+
<button @click="tabs.push('testt')">Add at the end</button>
5+
<button @click="tabs.unshift('new start')">Add one at start</button>
6+
<router-link to="/test">Go to a different route</router-link>
7+
<form-wizard @on-complete="onComplete"
8+
shape="circle"
9+
color="#e74c3c">
10+
<tab-content title="Personal details"
11+
route="/first"
12+
icon="ti-user">
13+
</tab-content>
14+
<tab-content title="Additional Info"
15+
route="/second"
16+
icon="ti-settings">
17+
</tab-content>
18+
<tab-content title="Last step"
19+
route="/third"
20+
icon="ti-check">
21+
</tab-content>
22+
<transition name="fade" mode="out-in">
23+
<router-view></router-view>
24+
</transition>
25+
26+
</form-wizard>
27+
</div>
28+
</template>
29+
30+
<script>
31+
import TabContent from "../src/components/TabContent";
32+
export default {
33+
components: {TabContent},
34+
data () {
35+
return {
36+
loadingWizard: false,
37+
error: null,
38+
count: 0,
39+
tabs: ['test', 'test2', 'test3']
40+
}
41+
},
42+
methods: {
43+
onComplete () {
44+
alert('Yay!')
45+
},
46+
setLoading (value) {
47+
this.loadingWizard = value
48+
},
49+
setError (error) {
50+
this.error = error
51+
},
52+
validateAsync () {
53+
//simulating an error for the first time and a success for the second time
54+
return new Promise((resolve, reject) => {
55+
setTimeout(() => {
56+
if (this.count % 2 === 0) {
57+
reject('Some custom error')
58+
} else {
59+
resolve(true)
60+
}
61+
this.count++
62+
}, 100)
63+
})
64+
},
65+
validate () {
66+
return true
67+
}
68+
}
69+
}
70+
</script>
71+
<style>
72+
@import "loader.css";
73+
</style>
74+
<style lang="scss">
75+
$border-radius-extreme: 6px !default;
76+
$white-color: white;
77+
$gray-input-bg: #F3F2EE !default;
78+
$card-black-color: #252422 !default;
79+
80+
body {
81+
margin-top: 20px;
82+
background-color: #ecf0f1;
83+
}
84+
85+
.card-footer {
86+
padding: 0px 20px;
87+
}
88+
89+
.card {
90+
border-radius: $border-radius-extreme;
91+
box-shadow: 0 2px 2px rgba(204, 197, 185, 0.5);
92+
background-color: $white-color;
93+
color: $card-black-color;
94+
padding: 10px 0;
95+
margin-bottom: 20px;
96+
position: relative;
97+
z-index: 1;
98+
}
99+
.fade-enter-active, .fade-leave-active {
100+
transition: opacity .2s
101+
}
102+
.fade-enter, .fade-leave-to /* .fade-leave-active in <2.1.8 */ {
103+
opacity: 0
104+
}
105+
</style>

dev-example/main.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,26 @@ import Vue from 'vue'
44
import VueRouter from 'vue-router'
55
import App from './App.vue'
66
import FormWizard from '../src/index'
7-
const First = { template: '<div>First page</div>' }
8-
const Second = { template: '<div>Second page</div>' }
9-
const Third = { template: '<div>Third page</div>' }
7+
import WizardRoute from './WizardRoute.vue'
8+
import TestRoute from './TestRoute.vue'
9+
10+
const First = {template: '<div>First page</div>'}
11+
const Second = {template: '<div>Second page</div>'}
12+
const Third = {template: '<div>Third page</div>'}
1013

1114
const router = new VueRouter({
1215
mode: 'history',
1316
routes: [
14-
{ path: '/first', component: First },
15-
{ path: '/second', component: Second },
16-
{ path: '/third', component: Third }
17+
{
18+
path: '/', component: WizardRoute,
19+
children: [
20+
{path: '/first', component: First},
21+
{path: '/second', component: Second},
22+
{path: '/third', component: Third}
23+
]
24+
},
25+
{path: '/test', component: TestRoute},
26+
1727
]
1828
})
1929
Vue.use(VueRouter)
@@ -25,6 +35,5 @@ Vue.config.productionTip = false
2535
new Vue({
2636
router,
2737
el: '#app',
28-
template: '<App/>',
29-
components: {App}
38+
render: h => h(App)
3039
})

src/components/FormWizard.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,11 @@
362362
activateTab (index) {
363363
this.deactivateTabs()
364364
let tab = this.tabs[index]
365-
tab.active = true
366-
tab.checked = true
367-
this.tryChangeRoute(tab)
365+
if (tab) {
366+
tab.active = true
367+
tab.checked = true
368+
this.tryChangeRoute(tab)
369+
}
368370
},
369371
activateTabAndCheckStep (index) {
370372
this.activateTab(index)

0 commit comments

Comments
 (0)