mirror of
https://github.com/tenrok/vue-form-wizard.git
synced 2026-06-19 22:40:33 +03:00
Merge pull request #161 from jvb93/more-event-hooks
Added afterTabChange functionality
This commit is contained in:
Generated
+11185
File diff suppressed because it is too large
Load Diff
@@ -280,6 +280,7 @@
|
|||||||
this.beforeTabChange(this.activeTabIndex, cb)
|
this.beforeTabChange(this.activeTabIndex, cb)
|
||||||
} else {
|
} else {
|
||||||
this.changeTab(this.activeTabIndex, index)
|
this.changeTab(this.activeTabIndex, index)
|
||||||
|
this.afterTabChange(this.activeTabIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (validate) {
|
if (validate) {
|
||||||
@@ -295,6 +296,7 @@
|
|||||||
let cb = () => {
|
let cb = () => {
|
||||||
if (this.activeTabIndex < this.tabCount - 1) {
|
if (this.activeTabIndex < this.tabCount - 1) {
|
||||||
this.changeTab(this.activeTabIndex, this.activeTabIndex + 1)
|
this.changeTab(this.activeTabIndex, this.activeTabIndex + 1)
|
||||||
|
this.afterTabChange(this.activeTabIndex)
|
||||||
} else {
|
} else {
|
||||||
this.$emit('on-complete')
|
this.$emit('on-complete')
|
||||||
}
|
}
|
||||||
@@ -377,6 +379,15 @@
|
|||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
afterTabChange (index) {
|
||||||
|
if (this.loading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let newTab = this.tabs[index]
|
||||||
|
if (newTab && newTab.afterChange !== undefined) {
|
||||||
|
newTab.afterChange()
|
||||||
|
}
|
||||||
|
},
|
||||||
changeTab (oldIndex, newIndex, emitChangeEvent = true) {
|
changeTab (oldIndex, newIndex, emitChangeEvent = true) {
|
||||||
let oldTab = this.tabs[oldIndex]
|
let oldTab = this.tabs[oldIndex]
|
||||||
let newTab = this.tabs[newIndex]
|
let newTab = this.tabs[newIndex]
|
||||||
|
|||||||
@@ -29,6 +29,13 @@
|
|||||||
*/
|
*/
|
||||||
beforeChange: {
|
beforeChange: {
|
||||||
type: Function
|
type: Function
|
||||||
|
},
|
||||||
|
/***
|
||||||
|
* Function to execute after tab switch. Return void for now.
|
||||||
|
* Safe to assume necessary validation has already occured
|
||||||
|
*/
|
||||||
|
afterChange: {
|
||||||
|
type: Function
|
||||||
},
|
},
|
||||||
route: {
|
route: {
|
||||||
type: [String, Object]
|
type: [String, Object]
|
||||||
|
|||||||
@@ -386,6 +386,50 @@ describe('FormWizard.vue', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
describe('after change', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
threeStepWizard = {
|
||||||
|
template: `<form-wizard>
|
||||||
|
<tab-content title="Personal details"
|
||||||
|
|
||||||
|
:after-change="validationMethod"
|
||||||
|
icon="ti-user">
|
||||||
|
My first tab content
|
||||||
|
</tab-content>
|
||||||
|
<tab-content title="Additional Info"
|
||||||
|
:after-change="validationMethod"
|
||||||
|
icon="ti-settings">
|
||||||
|
My second tab content
|
||||||
|
</tab-content>
|
||||||
|
<tab-content title="Last step"
|
||||||
|
icon="ti-settings">
|
||||||
|
My third tab content
|
||||||
|
</tab-content>
|
||||||
|
</form-wizard>`,
|
||||||
|
methods: {
|
||||||
|
validationMethod,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
it('simple method on after change', () => {
|
||||||
|
threeStepWizard.methods.validationMethod = sinon.stub()
|
||||||
|
threeStepWizard.methods.validationMethod.returns(null)
|
||||||
|
const wizard = mount(threeStepWizard, {localVue})
|
||||||
|
const wizardInstance = wizard.find(FormWizard)
|
||||||
|
wizardInstance.vm.nextTab()
|
||||||
|
expect(threeStepWizard.methods.validationMethod.should.have.been.called)
|
||||||
|
expect(wizardInstance.vm.activeTabIndex).to.equal(1)
|
||||||
|
})
|
||||||
|
it('simple method on back navigation after change', () => {
|
||||||
|
threeStepWizard.methods.validationMethod = sinon.stub()
|
||||||
|
threeStepWizard.methods.validationMethod.returns(null)
|
||||||
|
const wizard = mount(threeStepWizard, {localVue})
|
||||||
|
const wizardInstance = wizard.find(FormWizard)
|
||||||
|
wizardInstance.vm.nextTab()
|
||||||
|
wizardInstance.vm.prevTab()
|
||||||
|
expect(threeStepWizard.methods.validationMethod.should.have.been.called)
|
||||||
|
})
|
||||||
|
})
|
||||||
describe('with vue-router', ()=> {
|
describe('with vue-router', ()=> {
|
||||||
it('renders correct tab contents', () => {
|
it('renders correct tab contents', () => {
|
||||||
const wizard = mount(routerWizard, {localVue, router})
|
const wizard = mount(routerWizard, {localVue, router})
|
||||||
|
|||||||
Reference in New Issue
Block a user