Can we disable select2 field?

Can we disable select2 field?

zajczajc Posts: 67Questions: 10Answers: 2
edited April 2016 in Editor

I would like to disable select2 (version 4.0.1 or 4.0.2) field in editor. I tried this

editor.on( 'initEdit', function () {editor.disable('select2_field');} )

and got an error

select2.js:5530 Uncaught TypeError: Cannot read property 'apply' of undefined

This question has an accepted answers - jump to answer

Answers

  • zajczajc Posts: 67Questions: 10Answers: 2

    I have found the workaround.

                    editor
                        .on('open', function(e, mode, action) {
                          $('#DTE_Field_select2_field').prop("disabled", true);
                        });
    
  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    Thanks for noting that. I'll add the required methods and post back here when done.

    Allan

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin
    Answer ✓

    Actually, the plug-in does have the required methods, but they were using the Select2 3.x API rather than the 4.x API which has changed. The enable and disable methods for the plug-in should be:

        enable: function ( conf ) {
            $(conf._input).removeAttr( 'disabled' );
        },
    
        disable: function ( conf ) {
            $(conf._input).attr( 'disabled', 'disabled' );
        },
    

    I've updated the plug-in page with this change now.

    Thanks for flagging it up!

    Regards,
    Allan

  • zajczajc Posts: 67Questions: 10Answers: 2
    edited April 2016

    I have updated the plugin and disabled the field like this

    editor.disable('select2_field');
    

    and it works!

    Thanks :)

This discussion has been closed.