How can I Clone Chosen Plugin

前端 未结 1 577
抹茶落季
抹茶落季 2020-12-22 06:12

I wanted to use http://harvesthq.github.com/chosen/ witch jquery clone function:



        
相关标签:
1条回答
  • 2020-12-22 06:31

    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);
            }
        });
    };
    
    0 讨论(0)
提交回复
热议问题