Select2 plugin "set" method after "update" not working as expected (solution included)

Select2 plugin "set" method after "update" not working as expected (solution included)

zajczajc Posts: 67Questions: 10Answers: 2

When we update Select2 field with JSON

editor.field('select2_field').update(json);

and we set the value

editor.field('select2_field').set(value);

The value is not shown in the field in the editor (it is only set). If we would like the value to be shown we must extend the method "set" in the Select2 plugin

    set: function ( conf, val ) {
        conf._input.val( val );
    }

to

    set: function ( conf, val ) {
        conf._input.val( val ).trigger('change');
    }

according to discussion http://stackoverflow.com/questions/19639951/how-do-i-change-selected-value-of-select2-dropdown-with-jqgrid

I have tested this in Select2 4.0.1 and 4.0.2. I hope you will include this into the next Select2 plugin update.

Replies

  • narfetanarfeta Posts: 1Questions: 0Answers: 0

    cheeers mate! that was what i was looking for.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Hi,

    Thanks for letting me know about this and sorry for my delay in replying! It will indeed be in the next plug-in update.

    Regards,
    Allan

This discussion has been closed.