JQuery Select2 cannot enable after disable
See original GitHub issueI am using Select2 version 4.0.5.
My Code
php
<select class="form-control customer" disabled>
<option value=""></option>
@foreach($customer as $c)
<option value="{{ $c->id }}">{{ $c->user->name }}</option>
@endforeach
</select>
jquery
$(function() {
$('.customer').select2({
placeholder: "Choose Customer"
});
$('.customer').val(0).trigger('change.select2');
});
$('.action_add').on('click', function() {
$('.customer').select2('enable', false);
});
$('.action_delete').on('click', function() {
if(IsEmptyRow()) {
alert('test');
$('.customer').select2('enable', true);
}
});
Explanation
Enable false is working to make the select2 disable. When I want to enable it back, using enable true cannot make it enable back. The alert test inside the if code block is working.
System Details
Mac OS 10.13.5 PHP 7.0.9 Laravel 5.5
Issue Analytics
- State:
- Created 5 years ago
- Comments:20 (5 by maintainers)
Top Results From Across the Web
select2 disable / enabled not working - Stack Overflow
Basic jQuery seems to solve this problem quite nice: Enable: $("#list1").removeAttr('disabled');. Disable: $("#list1").attr('disabled' ...
Read more >Common problems - The jQuery replacement for select boxes
Select2 does not function properly when I use it inside a Bootstrap modal. This issue occurs because Bootstrap modals tend to steal focus...
Read more >Select2 3.5.3
Select2 JQuery Plugin. ... Note that when tagging is enabled the user can select from pre-existing tags or create a new tag by...
Read more >Select2 JQuery onChange disable Button
Unfortunately, with select2 plugins loaded in the component, onchange event is not firing. You can use aura:method ...
Read more >Enabling/Disabling select element using jQuery not working w
I solved it. I realized that you need removing the disabled attribute from the select element itself, too.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The
$('.customer').select2().prop("disabled", true);
still cannot enable it back.Hello @kevin-brown , The dropdown gets disabled , but once the dropdown is disabled, on clicking of space or enter keys , the drop down opens and we can change the values . Is there any other way we could disable it ? Have been trying out all the options here and have also looked into stackoverflow .