1

I have a select and a function bound to on change (ng-change), the thing is I want this function to work when the user clicks the already selected element, so they can easily reuse the already selected action.

This is my html (with Slim)

select ng-model="selectedAction" ng-options="action.label for action in Actions" ng-change="chooseAction()"
    option ng-selected="users.items.length == 0" value="" Select an Action

Is this possible or I'll have to add a button to make it work?

Already saw this and this, looking for another solution.

Community
  • 1
  • 1
LasagnaAndroid
  • 2,815
  • 1
  • 16
  • 20

2 Answers2

0

Is there any reason you can't just assign the same method to the ng-click attribute as well?

<select ng-model="selectedAction" ng-options="action.label for action in Actions" ng-change="chooseAction()" ng-click="chooseAction()">
Edward Coyle Jr.
  • 437
  • 2
  • 13
  • That just repeats the action on the select and doesn't work when clicking the already selected option, so that's the reason why I don't do that. I found a solution, but I'll wait to see if there's anything else before posting it. – LasagnaAndroid Nov 27 '14 at 18:20
  • 1
    If you have a solution please post it, it could be the best solution. If not it can be commented on and evolved. – Enzey Nov 27 '14 at 19:12
  • Added the "solution" I found. I think the only way to have something like this would be if you made your own select implementation or hacking something on top of `Select2.js` or some other `Select` library. – LasagnaAndroid Dec 12 '14 at 19:46
0

I couldn't detect if they clicked the same option again, so what I did was that everytime they chose an option, I would do this:

$scope.selectedAction = {
    label: 'Select an Action',
    id: 0
}

So it goes back to the default action.

LasagnaAndroid
  • 2,815
  • 1
  • 16
  • 20