victor-valencia / bootstrap-iconpicker

A simple icon picker
https://victor-valencia.github.com/bootstrap-iconpicker/
MIT License
377 stars 140 forks source link

Does not work when cloned #63

Open iLenTheme opened 7 years ago

iLenTheme commented 7 years ago

Hello, the plugin is promising and possibly the best in its kind. I have a problem like I do for the cloned iconpicker to work correctly, here's the example: https://jsfiddle.net/iLen/r87e5nh5/1/

help.

pbenard73 commented 7 years ago

Just have to set false as clone function argument.

The doc

The working fiddle

The code with toggle true to false in clone function

jQuery(".aaaa").iconpicker();
jQuery(".a_clone").on("click",function(){
    $(".aaaa").clone(false).insertAfter(".iconpicker_cloned");
        jQuery(".aaaa").iconpicker(); 
});
iLenTheme commented 7 years ago

With the clone: ​false this works fine, but if I do this I lose the events of the other input example: onclick, please check this example: example Please check param the .clone link

pbenard73 commented 7 years ago

Yes it could be better, but the main bundle seems to not be maintained....

Here is a hack just for your case : fiddle

$(".base_iconpicker").iconpicker();
$(".btn_clone").on("click",function(){
    var div_cloned = $(".div_to_clone").clone(true).removeClass('div_to_clone').insertAfter(".iconpicker_cloned");
       var errorClonePicker = div_cloned.find('.base_iconpicker');
      errorClonePicker.clone(false).insertAfter(errorClonePicker).iconpicker();
      errorClonePicker.remove(); 
});
$(".div_to_clone input[type='text']").on("click",function(){
    alert("event on click in text input");
});