Skip to content

Commit a77da7f

Browse files
committed
Check for canexit prior to running finish, update tests to pass
1 parent 9823e1f commit a77da7f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/wizard.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,17 @@ angular.module('mgo-angular-wizard').directive('wizard', function() {
335335

336336
//calls finish() which calls onFinish() which is declared on an attribute and linked to controller via wizard directive.
337337
this.finish = function() {
338-
if ($scope.onFinish) {
339-
$scope.onFinish();
340-
}
338+
var thisStepNumber = $scope.currentStepNumber() - 1;
339+
thisStepNumber = thisStepNumber < 0 ? 0 : thisStepNumber;
340+
var thisStep = $scope.getEnabledSteps()[thisStepNumber];
341+
342+
$q.when(canExitStep(thisStep, thisStep)).then(function(result) {
343+
if ($scope.onFinish) {
344+
$scope.onFinish();
345+
}
346+
}, function(error){
347+
$scope.$emit('wizard:finishFailed', {step: thisStep, index: _.indexOf($scope.getEnabledSteps(), thisStep)});
348+
});
341349
};
342350

343351
this.previous = function() {

test/angularWizardSpec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ describe( 'AngularWizard', function() {
320320
var view = createGenericView(scope);
321321
expect(scope.referenceCurrentStep).toEqual('Starting');
322322
WizardHandler.wizard().finish();
323+
$timeout.flush();
323324
expect(flag).toBeTruthy();
324325
$rootScope.$digest();
325326
});

0 commit comments

Comments
 (0)