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

csquillen avatar Jan 08 '14 17:01 csquillen

I'd rather get this working with ngRepeat and then you could use ngDisabled to disable the field as need

IgorMinar avatar Jan 13 '14 21:01 IgorMinar

+1

k-dauda avatar Feb 13 '14 00:02 k-dauda

+1

xcorat avatar Feb 17 '14 09:02 xcorat

+1

apuchkov avatar Feb 26 '14 20:02 apuchkov

@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.

paulovpereira avatar Mar 12 '14 14:03 paulovpereira

+1

BjornFridal avatar Mar 23 '14 21:03 BjornFridal

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>

tkrotoff avatar Mar 30 '14 23:03 tkrotoff

As for the first value (as a placeholder) I use.

<select ng-model"..." ng-options="...">
 <option value="" disabled selected>[Make your choise]</option>
</select>

hakanostrom avatar Apr 03 '14 08:04 hakanostrom

+1

hanchennz avatar Apr 17 '14 15:04 hanchennz

+1

mlegenhausen avatar Apr 24 '14 13:04 mlegenhausen

+1

martijn80 avatar Apr 24 '14 14:04 martijn80

+1 (@tkrotoff Thanks for the workaround :)

jonashw avatar Apr 25 '14 01:04 jonashw

+1

@hakanostrom

<select ng-model"..." ng-options="...">
 <option value="" disabled selected>[Make your choice]</option>
</select>

does that actually work for you? when i do this it always selects the first (selectable) option, not the default disabled option :(

connorbode avatar Apr 28 '14 20:04 connorbode

@connorbode @hakanostrom I have the same issue with

<select ng-model"..." ng-options="...">
 <option value="" disabled selected>[Make your choice]</option>
</select>

and Firefox. Chrome and IE11 works fine.

m4r71n avatar May 19 '14 07:05 m4r71n

+1 ng-repeat cannot achieve group by easily.

Hope for syntax like

select as label disable if cond group by group for value in array

cades avatar Jun 23 '14 05:06 cades

+1

steffenkuche avatar Jul 08 '14 14:07 steffenkuche

+1

lukeychelt avatar Jul 09 '14 10:07 lukeychelt

+1

rhys-vdw avatar Jul 10 '14 06:07 rhys-vdw

+1

mustela avatar Jul 11 '14 11:07 mustela