chosen with bootstrap 3 not working properly

后端 未结 6 715
醉话见心
醉话见心 2020-12-08 04:19

I have this code which triggers a bootstrap modal and load its content via $.load(). the page I\'m loading has a select element which I\'m calling chosen on. He

6条回答
  •  [愿得一人]
    2020-12-08 05:13

    Applying Chosen after the modal is shown should solve your problem:

    $('#myModal').on('shown.bs.modal', function () {
      $('.chosen-select', this).chosen();
    });
    

    Or when Chosen was already applied, destroy and reapply:

    $('#myModal').on('shown.bs.modal', function () {
      $('.chosen-select', this).chosen('destroy').chosen();
    });
    

    Fiddle here: http://jsfiddle.net/koenpunt/W6dZV/

    So in your case it would probably something like:

    $('.someClick').click(function(e){
       e.preventDefault();
       x.modal('show');
       x.on('shown.bs.modal', function(){
           x.find('.modal-body').load('path/page.html', function(response, status, xhr){
               if(status == "success"){
                   $("select[name=elementName]").chosen();
               }
           });
       });
    });
    

    EDIT

    To complement Chosen you can use the Chosen Bootstrap theme

提交回复
热议问题