Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chosen jquery. how can I change from multiselect to single

I have chosen multiselectable.I want to change chosen from multiselect to single select on javascript code. I will send some ajax post and according to response value, I must change property of chosen. From multiselect to singleselect or oppsitely.

like image 325
Ibrohim Ermatov Avatar asked Nov 01 '22 13:11

Ibrohim Ermatov


1 Answers

I ended up having to manually destroy the Chosen instance, change the multiple attribute of the raw select element, and initialize the plugin again.

var $select = $('.my-select');
$select.chosen('destroy');
$select.attr('multiple', 'multiple');
$select.chosen();

or the inverse

$select.chosen('destroy'); 
$select.removeAttr('multiple');
$select.chosen();

Not super clean but Chosen doesn't appear to have a "rerender from source element" method, other than changes to the options.

like image 128
justisb Avatar answered Nov 09 '22 06:11

justisb