Skip to content

Commit 9d4315e

Browse files
author
Jacob Carter
committed
Merge branch 'JacobJust-master'
2 parents f637ede + 2c26c7b commit 9d4315e

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ angular.module('your-app', ['mgo-angular-wizard']);
4747
Now, in some HTML for a controller, you can just add a wizard as follows:
4848

4949
````html
50-
<wizard on-finish="finishedWizard()">
50+
<wizard on-finish="finishedWizard()" on-cancel="cancelledWizard()">
5151
<wz-step wz-title="Starting">
5252
<h1>This is the first step</h1>
5353
<p>Here you can use whatever you want. You can use other directives, binding, etc.</p>
@@ -73,6 +73,7 @@ Let's go step by step to see how this works.
7373

7474
1) You need to declare a master `wizard` directive. This wizard directive, has the following options as attributes:
7575
* **on-finish**: Here you can put a function to be called when the wizard is finished. The syntax here is very similar to `ng-click`
76+
* **on-cancel**: Here you can put a function to be called when the wizard is cancelled. The syntax here is very similar to `ng-click`
7677
* **name**: The name of the wizard. By default, it's called "Default wizard". It's used for the `WizardHandler` which we'll explain later.
7778
* **edit-mode**: If set to true, this will set the wizard as edit mode. Edit mode means that all steps have been completed and the user can now navigate to and modify any step. Defaults to false.
7879
* **hide-indicators**: If set to true, the indicators in the bottom of the page showing the current page and allowing navigation for the wizard will be hidden. Defaults to false.
@@ -91,7 +92,7 @@ Let's go step by step to see how this works.
9192

9293
3) Inside the step, we now see a button which has a `wz-next` attribute. That means that clicking that button will send the user to the next step of wizard. Similar to `wz-next`, we have the following attributes:
9394
* **wz-previous**: Goes to the previous step
94-
* **wz-cancel**: Goes back to the first step
95+
* **wz-cancel**: Calls on-cancel if defined, otherwise the default action is to go back to the first step
9596
* **wz-finish**: Finishes the wizard and calls the on-finish later on. It's important to note that if we're in the last step and we put `wz-next` it'll be the same as putting `wz-finish` as the wizard will know we're at the last screen.
9697
* **wz-reset**: This will reset the wizard meaning bring the user to the first step and reset each step to being incomplete.
9798

@@ -110,7 +111,7 @@ A step can be conditionally disabled and may change at any time either adding it
110111

111112
HTML
112113
````html
113-
<wizard on-finish="finishedWizard()">
114+
<wizard on-finish="finishedWizard()" on-cancel="cancelledWizard()">
114115
<wz-step wz-title="Starting" wz-disabled="{{disabled}}">
115116
<h1>This is the first step</h1>
116117
<p>Here you can use whatever you want. You can use other directives, binding, etc.</p>
@@ -143,7 +144,7 @@ The wzStep directive has the following options as attributes:
143144

144145
HTML
145146
````html
146-
<wizard on-finish="finishedWizard()">
147+
<wizard on-finish="finishedWizard()" on-cancel="cancelledWizard()">
147148
<wz-step wz-title="Starting" canexit="exitValidation">
148149
<h1>This is the first step</h1>
149150
<p>Here you can use whatever you want. You can use other directives, binding, etc.</p>

‎src/wizard.js‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ angular.module('mgo-angular-wizard').directive('wizard', function() {
66
transclude: true,
77
scope: {
88
currentStep: '=',
9+
onCancel: '&',
910
onFinish: '&',
1011
hideIndicators: '=',
1112
editMode: '=',
@@ -167,6 +168,8 @@ angular.module('mgo-angular-wizard').directive('wizard', function() {
167168
//emit event upwards with data on goTo() invoktion
168169
$scope.$emit('wizard:stepChanged', {step: step, index: stepIdx(step)});
169170
//$log.log('current step number: ', $scope.currentStepNumber());
171+
} else {
172+
$scope.$emit('wizard:stepChangeFailed', {step: step, index: _.indexOf($scope.getEnabledSteps(), step)});
170173
}
171174
});
172175
}
@@ -339,14 +342,19 @@ angular.module('mgo-angular-wizard').directive('wizard', function() {
339342

340343
//cancel is alias for previous.
341344
this.cancel = function() {
342-
//getting index of current step
343-
var index = stepIdx($scope.selectedStep);
344-
//ensuring you aren't trying to go back from the first step
345-
if (index === 0) {
346-
throw new Error("Can't go back. It's already in step 0");
345+
if ($scope.onCancel) {
346+
//onCancel is linked to controller via wizard directive:
347+
$scope.onCancel();
347348
} else {
348-
//go back one step from current step
349-
$scope.goTo($scope.getEnabledSteps()[0]);
349+
//getting index of current step
350+
var index = stepIdx($scope.selectedStep);
351+
//ensuring you aren't trying to go back from the first step
352+
if (index === 0) {
353+
throw new Error("Can't go back. It's already in step 0");
354+
} else {
355+
//go back one step from current step
356+
$scope.goTo($scope.getEnabledSteps()[0]);
357+
}
350358
}
351359
};
352360

0 commit comments

Comments
 (0)