question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JQuery Select2 cannot enable after disable

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
conangithubcommented, Aug 6, 2018

The $('.customer').select2().prop("disabled", true); still cannot enable it back.

1reaction
hariharan-baskarancommented, Jul 25, 2019

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 .

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found