Cloned Select2 is not responding

前端 未结 13 2424
长发绾君心
长发绾君心 2020-11-29 03:51

I am trying to clone a row which contains select2 tool ,when i clone that row using jQuery the cloned select2 is not responding.In image given below first select2 which is o

13条回答
  •  臣服心动
    2020-11-29 04:20

    I've actually created account to answer this, since it took me a while to make it work.

    This is not working when used before cloning: $('.selectpicker').select2('destroy')

    But this works in my case:

    $('.selectpicker').select2('destroy');
    $('.selectpicker')
        .removeAttr('data-live-search')
        .removeAttr('data-select2-id')
        .removeAttr('aria-hidden')
        .removeAttr('tabindex');
    

    Just remove all the additional attributes which select2 adds.

    Edit #1

    Ok so seems like You also got to remove ID from the element that is being cloned since select2 tries to add it's own unique id when none is found on the select, but when You do have select it's getting messy and selet2 attaches only on the last element with the same ID.

提交回复
热议问题