Select2 disable not working...

Select2 disable not working...

kaustubh.agrawal2000kaustubh.agrawal2000 Posts: 81Questions: 35Answers: 2

I am using select2 plugin, although it works well, I have a use case where i should disable option select during edits.
which I am doing like:

editor.on( 'initEdit', function ( e, json, data ) {
        editor.disable('commodity_id');
        editor.disable('transaction_type');
});

Here, commodity_id & transaction_type are both select2 fields.. values of which are populated by AJAX.
The fields on the form are shown as GREYED OUT (like disabled).. but I am still able to select the options...

How can I disable that ?

Steps to reproduce

GOTO: https://gadhiya.in
Login
  - UNAME: sunil.gadhiya@gmail.com
  - PWD : 12345678
 
Clear browser cache
GOTO: https://gadhiya.in/parameter
TRY Editing any of the rows..
The commodity field is disabled but still the select options are shown and selectable.

Regards
Kaustubh

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 48,296Questions: 1Answers: 6,969 Site admin
    Answer ✓

    You have this in common.js which is causing the list to open:

    $(document).on('focus', '.select2.select2-container', function (e) {
        // only open on original attempt - close focus event should not fire open
        if (e.originalEvent && $(this).find(".select2-selection--single").length > 0) {
          $(this).siblings('select').select2('open');
        }
    });
    

    Allan

  • kaustubh.agrawal2000kaustubh.agrawal2000 Posts: 81Questions: 35Answers: 2

    Thanks a lot Allan..
    You are awesome...

    BTW, can you please let me know, what tools do you use to debug JS ?
    I find it particularly difficult to track JS events....

Sign In or Register to comment.