-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Support disabling options in select with ng:options #638
Comments
+1 |
1 similar comment
+1 |
I put together a directive as a hack around this limitation: http://jsfiddle.net/alalonde/dZDLg/5/ YMMV. What would a good syntax be to implement this in ng-options? |
+1 model [{id: 1, title: 'Credit card'},{id:4, title: 'For free'}, {id: 7, title: 'Dont want it'}] when i want to disable i.e. "for free" option, you have to iterate through model and take array position for "For free" object (i.e 1). Problem is when angular ads empty option: Credit card For free Dont want itmodel[i] is shifted against expected data, so option[1] is "Credit card" not "For free"... |
Yes, I have added a number of enhancement to the directive in the meantime. Here is an updated version that should fix your problem: http://jsfiddle.net/alalonde/dZDLg/9/ |
Thank you so much alalonde, you saved my day! |
+1 |
1 similar comment
+1 |
It's very wierd. It works but it disables the previous option, so changing from |
+1 |
2 similar comments
+1 |
+1 |
+1 |
as for data[i-1] - this is in general wrong, because 1 should be replaced number of options in HTML template. |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
Custom directive without jQuery dependency. http://stackoverflow.com/a/20790905/1283546 @borteo - Check this out! |
+1 |
I'd rather get this working with ngRepeat and then you could use ngDisabled to disable the field as need |
+1 |
2 similar comments
+1 |
+1 |
@IgorMinar I've tried this aproaching, but it added some levels of complexity to the management of ng-model (list of ids) since I had to work with Strings istead of Integer to keep the Select element selecting the right options. And besides, its much more verbose with ng-repeat. |
+1 |
Edit: select & option with ng-repeat gave me some issues (I guess that's why ng-options exists in the first place), I went for having multiple select with ng-options and hide/show them depending on the context Instead of using a new directive (the jsfiddles from above) you can simply use ng-repeat: <select ng-model="item.status">
<option ng-repeat="status in statusList"
ng-selected="status.value === item.status"
value="{{status.value}}"
ng-disabled="status.value === '42'">
{{status.text}}
</option>
</select> |
As for the first value (as a placeholder) I use. <select ng-model"..." ng-options="...">
<option value="" disabled selected>[Make your choise]</option>
</select> |
+1 |
This patch adds support for disabling options based on model values. The "disable when" syntax allows for listening to changes on those model values, in order to dynamically enable and disable the options. The changes prevent disabled options from being written to the selectCtrl from the model. If a disabled selection is present on the model, normal unknown or empty functionality kicks in. closes angular#638
This patch adds support for disabling options based on model values. The "disable when" syntax allows for listening to changes on those model values, in order to dynamically enable and disable the options. The changes prevent disabled options from being written to the selectCtrl from the model. If a disabled selection is present on the model, normal unknown or empty functionality kicks in. closes angular#638
This patch adds support for disabling options based on model values. The "disable when" syntax allows for listening to changes on those model values, in order to dynamically enable and disable the options. The changes prevent disabled options from being written to the selectCtrl from the model. If a disabled selection is present on the model, normal unknown or empty functionality kicks in. closes angular#638
This patch adds support for disabling options based on model values. The "disable when" syntax allows for listening to changes on those model values, in order to dynamically enable and disable the options. The changes prevent disabled options from being written to the selectCtrl from the model. If a disabled selection is present on the model, normal unknown or empty functionality kicks in. Closes angular#638 Closes angular#11017
I think this is applicable while there is no way to do this via <option ng-repeat="option in myOptions" value="{{ option.key }}" ng-disabled="option.disabled">
{{ option.label }}
</option> $scope.myOptions = [{
key: 'key1',
label: 'Key #1'
}, {
key: 'key2',
label: 'Key #2',
disabled: true
}]; |
ng-repeat on option doesn't work in IE (at least IE8). It was mentioned here #638 (comment) |
This patch adds support for disabling options based on model values. The "disable when" syntax allows for listening to changes on those model values, in order to dynamically enable and disable the options. The changes prevent disabled options from being written to the selectCtrl from the model. If a disabled selection is present on the model, normal unknown or empty functionality kicks in. Closes angular#638 Closes angular#11017
In this example: http://jsfiddle.net/alalonde/dZDLg/9/ Set value from test to null for selectedPort variable like this $scope.selectedport = null; Thanks |
When the this directive http://jsfiddle.net/alalonde/dZDLg/9/ is used inside ag-grid,The disbled property is not applied to he options until we do a selection in the select box. could you please help on this? |
@anilkganhari, since you seem to be using angular-options-disabled, you should probably ask the question in their repo. This is not related to core Angular. BTW, the |
Still nothing native to Angular ? |
@fredericlam, see #638 (comment). |
@gkalpak Wow, sorry, and thanks |
funka capo! bien ahi alto team...estoy sin celular no me funcionan los 2015-11-25 13:35 GMT-03:00 Dishant Mehta [email protected]:
|
Need a way to construct
There's no way to express the disabled state of a specific option with ng:options
The text was updated successfully, but these errors were encountered: