Chosen dropdown list not working with Modal

邮差的信 提交于 2019-12-05 08:36:32

I can't exactly tell what the problem is without seeing your actual code structure, but generally I think it's a good idea to populate you selects before initializing the plugin, so the best approach would be to add the plugin initialization on your elements in your ajax callback after the options have been added.

var callbackSuccess = function(data){
    if ( data ) {
        populateDropDownById(data, 'objectiveBanks');
        $(".chzn-select").chosen();
        $(".chzn-select-deselect").chosen({allow_single_deselect:true});
        //Other things
    }
};

If you need to add options to your <select> elements after the plugin is initialized, you'd need to trigger the chosen:updated event on the field, ex:

$(.chzn-select").trigger("chosen:updated");

I had a similar problem with a select on the first page, and then I would open a modal, and then the call to $().chosen() would result in a javascript error.

The cause was that the first page included jquery.js and so did the modal. After removing the jquery.js include from the modal, the problem was solved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!