angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Support disabling options in select with ng:options

Open esprehn opened this issue 15 years ago • 96 comments

Need a way to construct

<select>
  <option disabled>A</option>
  <option>B</option>
  <optionC</option>
</select>

There's no way to express the disabled state of a specific option with ng:options

esprehn avatar Nov 05 '11 22:11 esprehn

+1

jBox avatar Jan 22 '15 02:01 jBox

+1

janeklb avatar Jan 23 '15 12:01 janeklb

Made up a quick directive here - https://github.com/knivets/angular-options-disabled

knivets avatar Jan 24 '15 22:01 knivets

+1

giladbeeri avatar Jan 28 '15 14:01 giladbeeri

+1

also It good to have some functionality to skip particular option

For eg.

ng-options="page.id as page.name for page in pages" ng-option-skip="page.id === 100"

the above code should skip rendering an option html when particular psge.id value is 100 in this case.

PS: ng-if can be used here, but it would be better if ng-option itself has some functionality.

jparmar avatar Jan 30 '15 05:01 jparmar

@jparmar: Wouldn't you use a filter in that case to modify the collection that ng-options is rendering? This enhancement is needed because you still want to render an item in the collection as an option, but have it be disabled, which a filter won't help you with.

greglockwood avatar Jan 30 '15 08:01 greglockwood

@knivets @chadreed-intl +1 for the dynamic options issue.

@chadreed-intl Did you find a solution to make it work for dynamic options? I'm having a hard time figuring it out!

rutwick avatar Jan 30 '15 11:01 rutwick

I think this is applicable while there is no way to do this via ng-options:

<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
}];

ivkremer avatar Jun 11 '15 15:06 ivkremer

ng-repeat on option doesn't work in IE (at least IE8). It was mentioned here https://github.com/angular/angular.js/issues/638#issuecomment-51002615

Xartok avatar Jun 11 '15 17:06 Xartok

@alalonde

In this example: http://jsfiddle.net/alalonde/dZDLg/9/

Set value from test to null for selectedPort variable like this $scope.selectedport = null; The code will break...It does not disable untill we select some option... Could you help me how to fix this issue?

Thanks Prem.

premboyapati avatar Aug 26 '15 16:08 premboyapati

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 avatar Jan 10 '16 11:01 anilkganhari

@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 ngOptions DSL now supports "disable when" for disabling specific options (see docs). (Make sure that your Angular version has this feature, before using it.)

gkalpak avatar Jan 10 '16 15:01 gkalpak

Still nothing native to Angular ?

fredericlam avatar Feb 23 '16 13:02 fredericlam

@fredericlam, see https://github.com/angular/angular.js/issues/638#issuecomment-170361383.

gkalpak avatar Feb 23 '16 15:02 gkalpak

@gkalpak Wow, sorry, and thanks

fredericlam avatar Feb 23 '16 16:02 fredericlam

funka capo! bien ahi alto team...estoy sin celular no me funcionan los botones, calculo que el sabado como mucho lo cambio, mientras tanto nos comunicamos por este medio

2015-11-25 13:35 GMT-03:00 Dishant Mehta [email protected]:

you can fix this bug like Test 1 Test 2

— Reply to this email directly or view it on GitHub https://github.com/angular/angular.js/issues/638#issuecomment-159664164.

LucasFrecia avatar Feb 24 '16 02:02 LucasFrecia