Skip to content

Commit

Permalink
feat ($ionicActionSheet): pass button object to buttonClicked
Browse files Browse the repository at this point in the history
Closes #1369.

Right now `buttonClicked` accepts only the index of the pressed button that means you have to work with indices to decide which one it is. In case you move buttons around to get better UX, you'd have to be very careful with those indices. It's easier to add `id` property to buttons and simply check for it. Index-agnostic solution is more maintainable and leads to less changes to the code when the buttons order is being changed.
  • Loading branch information
xaka authored and ajoslin committed May 13, 2014
1 parent 0c960b5 commit e0c7979
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions js/angular/service/actionSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
* - `{string=}` `destructiveText` The text for a 'danger' on the action sheet.
* - `{function=}` `cancel` Called if the cancel button is pressed or the backdrop is tapped.
* - `{function=}` `buttonClicked` Called when one of the non-destructive buttons is clicked,
* with the index of the button that was clicked. Return true to close the action sheet,
* or false to keep it opened.
* with the index of the button that was clicked and the button object. Return true to close
* the action sheet, or false to keep it opened.
* - `{function=}` `destructiveButtonClicked` Called when the destructive button is clicked.
* Return true to close the action sheet, or false to keep it opened.
*/
Expand All @@ -80,7 +80,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
extend(scope, {
cancel: angular.noop,
buttonClicked: angular.noop,
destructiveButtonClicked: angular.noop
destructiveButtonClicked: angular.noop,
buttons: []
}, opts);

// Compile the template
Expand Down Expand Up @@ -121,7 +122,7 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
scope.buttonClicked = function(index) {
// Check if the button click event returned true, which means
// we can close the action sheet
if((opts.buttonClicked && opts.buttonClicked(index)) === true) {
if((opts.buttonClicked && opts.buttonClicked(index, opts.buttons[index])) === true) {
hideSheet(false);
}
};
Expand Down

0 comments on commit e0c7979

Please sign in to comment.