disable jquery-chosen dropdown

前端 未结 7 1984
深忆病人
深忆病人 2021-02-01 11:52

I have a select div that I\'m using the chosen jquery plugin to style and add features to (most notably, search). The div looks something like this,

 
                        
    
提交评论

  • 2021-02-01 12:05
    $(document).ready(function () {
        $("#foobar").chosen().on('chosen:showing_dropdown',function() {
                $('.chosen-select').attr('disabled', true).trigger('chosen:updated');
                $('.chosen-select').attr('disabled', false).trigger('chosen:updated');
                $('.search-choice-close').hide();
        });
        $('.search-choice-close').hide();
    });
    
    0 讨论(0)
  • 2021-02-01 12:06

    In the lastest version of chosen, liszt:updated is not working anymore. You need to use chosen:updated:

    $(".chosen-select").attr('disabled', true).trigger("chosen:updated")
    

    Here's a JSFiddle.

    0 讨论(0)
  • 2021-02-01 12:17

    PSL was correct, but chosen has been updated since.

    Put this after you do the disabling:

    $("#your-select").trigger("chosen:updated");
    
    0 讨论(0)
  • 2021-02-01 12:22
    $("chosen_one").chosen({
      max_selected_options: -1
    });
    
    0 讨论(0)
  • 2021-02-01 12:24

    You can try this:

    $("#foobar").prop('disabled',true).trigger("chosen:updated").chosen('destroy').chosen()
    
    0 讨论(0)
  • 提交回复
    热议问题