From 2ef766c7d96a4616c65655985a9df0cc0b517d46 Mon Sep 17 00:00:00 2001 From: micahcourey Date: Tue, 11 Jul 2017 21:25:07 -0700 Subject: [PATCH 1/3] Add revertToStep method to handle server errors after pressing done by returning user to previous step --- src/wizard.component.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wizard.component.ts b/src/wizard.component.ts index 8953f89a..ad1f94cb 100644 --- a/src/wizard.component.ts +++ b/src/wizard.component.ts @@ -1,4 +1,4 @@ -import { Component, Output, EventEmitter, ContentChildren, QueryList, AfterContentInit } from '@angular/core'; +import { Component, Output, Input, EventEmitter, ContentChildren, QueryList, AfterContentInit } from '@angular/core'; import { WizardStepComponent } from './wizard-step.component'; @Component({ @@ -41,6 +41,7 @@ export class WizardComponent implements AfterContentInit { private _steps: Array = []; private _isCompleted: boolean = false; + @Input() forceStep: number; @Output() onStepChanged: EventEmitter = new EventEmitter(); @@ -48,9 +49,17 @@ export class WizardComponent implements AfterContentInit { ngAfterContentInit() { this.wizardSteps.forEach(step => this._steps.push(step)); - this.steps[0].isActive = true; + if (this.steps.length) { + this.steps[0].isActive = true; + } } + public revertToStep(stepIndex: any) { + this._isCompleted = false; + let nextStep: WizardStepComponent = this.steps[stepIndex]; + this.goToStep(nextStep); + }; + get steps(): Array { return this._steps.filter(step => !step.hidden); } From 9cb4da39b1b8afbc2c6c2ebbdde2915fa7edf49e Mon Sep 17 00:00:00 2001 From: micahcourey Date: Thu, 13 Jul 2017 21:08:41 -0700 Subject: [PATCH 2/3] Add OnChanges to watch for forceStep and then revert to the specified step. --- src/wizard.component.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/wizard.component.ts b/src/wizard.component.ts index ad1f94cb..25868a29 100644 --- a/src/wizard.component.ts +++ b/src/wizard.component.ts @@ -1,8 +1,8 @@ -import { Component, Output, Input, EventEmitter, ContentChildren, QueryList, AfterContentInit } from '@angular/core'; +import { Component, Output, Input, EventEmitter, ContentChildren, QueryList, AfterContentInit, OnChanges } from '@angular/core'; import { WizardStepComponent } from './wizard-step.component'; @Component({ - selector: 'form-wizard', + selector: 'wizard', template: `
@@ -34,7 +34,7 @@ import { WizardStepComponent } from './wizard-step.component'; '.completed { cursor: default; }' ] }) -export class WizardComponent implements AfterContentInit { +export class WizardComponent implements AfterContentInit, OnChanges { @ContentChildren(WizardStepComponent) wizardSteps: QueryList; @@ -54,11 +54,11 @@ export class WizardComponent implements AfterContentInit { } } - public revertToStep(stepIndex: any) { - this._isCompleted = false; - let nextStep: WizardStepComponent = this.steps[stepIndex]; - this.goToStep(nextStep); - }; + ngOnChanges() { + if (this.forceStep) { + this.revertToStep(this.forceStep); + } + } get steps(): Array { return this._steps.filter(step => !step.hidden); @@ -98,6 +98,12 @@ export class WizardComponent implements AfterContentInit { } } + public revertToStep(stepIndex: any) { + this._isCompleted = false; + let nextStep: WizardStepComponent = this.steps[stepIndex]; + this.goToStep(nextStep); + }; + public next(): void { if (this.hasNextStep) { let nextStep: WizardStepComponent = this.steps[this.activeStepIndex + 1]; From a7943b26ceeb466477ccca783a7bda9d445f11ea Mon Sep 17 00:00:00 2001 From: micahcourey Date: Thu, 13 Jul 2017 21:21:17 -0700 Subject: [PATCH 3/3] Change component selector back to form-wizard --- src/wizard.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wizard.component.ts b/src/wizard.component.ts index 25868a29..07126888 100644 --- a/src/wizard.component.ts +++ b/src/wizard.component.ts @@ -2,7 +2,7 @@ import { Component, Output, Input, EventEmitter, ContentChildren, QueryList, Aft import { WizardStepComponent } from './wizard-step.component'; @Component({ - selector: 'wizard', + selector: 'form-wizard', template: `