option が disabled の時の jQuery の select multiple に対する val の挙動
<select multiple> <option>foo</option> <option disabled selected>bar</option> </select>
上のような select を用いた時に、jQuery で選択中の値を取得しようとすると disabled
な option は省かれてしまう。
jquery/val.js at 56136897f241db22560b58c3518578ca1453d5c7 · jquery/jquery · GitHub
bootstrap-select が上手く動かなくて気づいた。
w3c を見ても
The disabled attribute is a boolean attribute. An option element is disabled if its disabled attribute is present or if it is a child of an optgroup element whose disabled attribute is present. An option element that is disabled must prevent any click events that are queued on the user interaction task source from being dispatched on the element.
と書いてあって、省くような記述はない。
また、<disabled option element>.selected
は true
を返すし、 <select element>.selectedOptions
では disabled
のも帰ってくる。
調べてみたら、どうやらそういうものらしい…。
javascript - Get Value of Disabled Option in Select Multiple Jquery - Stack Overflow