How can I Clone Chosen Plugin

倖福魔咒の 提交于 2019-11-29 17:52:28

I would add a condition to the clear inputs area to check for selects with the .chz-select class and perform the re-initialization as in the answer you linked:

UPDATE

Since you're cloning using the true parameter, you need to remove the data from the element before reinitializing it, also I found an issue with the chosen plugin not getting the calculated width of the element after adding display:inline-block; so I had to use a timeout to introduce a minimal delay before the reinitialization

//Clear Inputs/Textarea
if (settings.clearInputs){
    $(clone).find(':input').each(function(){
        var type = $(this).attr('type');
        switch(type)
        {
            case "button":
                   break;
            case "reset":
                   break;
            case "submit":
                   break;
            case "checkbox":
                   $(this).attr('checked', '');
                   break;
            default:
                   $(this).val("");
        }
        if ($(this).hasClass('chzn-select')) {
            $(this).next('.chzn-container').remove();
            $(this).css({display: "inline-block"}).removeClass("chzn-done");
            var that = $(this);
            setTimeout(function () {
                that.removeData('chosen').chosen();
            }, 0);
        }
    });
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!