admin管理员组文章数量:1292361
I want to ask about select2
. I want, when I choose the option it will be hidden from the options in the select. And also if we remove it in multiple select option, it will be showed too in the option. The cases is when I'm using prop('disabled', true), It's works. But, when I'm using prop('hidden', true), It's not hidden properly.
$(document).on("select2:select", "#multiple_one, #multiple_two", function(e) {
updateSelections(e.params.data.id);
});
$(document).on("select2:unselect", "#multiple_one, #multiple_two", function(e) {
updateSelectionsTwo(e.params.data.id);
});
I'm using event select2:select
and select2:unselect
function updateSelections(selectedValue) {
// console.log(selectedValue);
$("#multiple_one option[value='" + selectedValue + "']").prop('disabled', true)
$("#multiple_two option[value='" + selectedValue + "']").prop('disabled', true)
// $("#multiple_one").select2("destroy").select2();
}
The code is using disabled property. Could I use hidden property if it's already selected? And show again if the option is unselected?
I want to ask about select2
. I want, when I choose the option it will be hidden from the options in the select. And also if we remove it in multiple select option, it will be showed too in the option. The cases is when I'm using prop('disabled', true), It's works. But, when I'm using prop('hidden', true), It's not hidden properly.
$(document).on("select2:select", "#multiple_one, #multiple_two", function(e) {
updateSelections(e.params.data.id);
});
$(document).on("select2:unselect", "#multiple_one, #multiple_two", function(e) {
updateSelectionsTwo(e.params.data.id);
});
I'm using event select2:select
and select2:unselect
function updateSelections(selectedValue) {
// console.log(selectedValue);
$("#multiple_one option[value='" + selectedValue + "']").prop('disabled', true)
$("#multiple_two option[value='" + selectedValue + "']").prop('disabled', true)
// $("#multiple_one").select2("destroy").select2();
}
The code is using disabled property. Could I use hidden property if it's already selected? And show again if the option is unselected?
Share Improve this question edited Feb 13 at 9:05 mplungjan 178k28 gold badges181 silver badges240 bronze badges asked Feb 13 at 8:44 Filbert UmbawaFilbert Umbawa 113 bronze badges 1 |2 Answers
Reset to default 0It's already done, the hidden property or etc isn't appear in select2 component. Only have disabled property. So, we combined the selector aria-disabled="true"
in css.
<li class="select2-results__option" id="select2-multiple_one-result-nqh8-1" role="option" aria-disabled="true" data-select2-id="select2-multiple_one-result-nqh8-1">BIAYA BURUH</li>
With this css
.select2-results__option[aria-disabled="true"] {
display: none;
}
Maybe it will help. Thanks.
I don't think html element has "hidden" attribute, maybe you need to use css "display: none".
本文标签: javascriptProp hidden() or hide() and show() can39t used in Select2 Multiple OptionStack Overflow
版权声明:本文标题:javascript - Prop hidden() or hide() and show() can't used in Select2 Multiple Option - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741554636a2385079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
[<>]
snippet editor and select2 framework from CDN – mplungjan Commented Feb 13 at 8:52