Support disabling options in select with ng:options
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
+1
+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 your directive is very good, but not sufficient:
model [{id: 1, title: 'Credit card'},{id:4, title: 'For free'}, {id: 7, title: 'Dont want it'}] select will looks like this:
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:
model[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
It's very wierd. It works but it disables the previous option, so changing from locals[attr] = data[i]; to locals[attr] = data[i-1]; did the trick. I've tested it by placing a disabled: true property on the first and last item from the object to see if something breaks, but didn't break anything... it just works :)
+1
+1
+1
+1 Would be great having no dependency to jQuery
as for data[i-1] - this is in general wrong, because 1 should be replaced number of options in HTML template.
+1
+1
+1
+1
+1
Custom directive without jQuery dependency.
http://stackoverflow.com/a/20790905/1283546
@borteo - Check this out!