jQuery Chosen plugin without search field

前端 未结 12 869
时光说笑
时光说笑 2021-02-05 02:45

Not sure if this has been covered somewhere, but I couldn\'t find it in the documentation, and was wondering if it\'d be possible to not include the search input box with the jQ

相关标签:
12条回答
  • 2021-02-05 03:01

    With the latest Version of chosen only that works for me:

    $('ul.chosen-choices li.search-field').hide();
    
    0 讨论(0)
  • 2021-02-05 03:02

    Use this code to disable it:

    jQuery('select').chosen( {disable_search: true} );
    

    and don't forget to hide it, otherwise it will still be working on mobile !

    .chzn-search{display: none}
    
    0 讨论(0)
  • 2021-02-05 03:02
    $('select').chosen( {disable_search: true} );
    
    0 讨论(0)
  • 2021-02-05 03:09

    Newer versions of jquery chosen gives you option to disable search input with in dropdown.

    $(".chzn-select").chosen({
       disable_search: true
    });
    

    Older versions do not support this option. Some how if you are strictly not allowed to use newer version than you can use

    $(".chzn-select").chosen({
       disable_search_threshold: 5
    });
    

    it will hide the search box if results are less than 5, best to use with gender type dropdowns. There is another way to fix this and that is;

    $(".chzn-select").chosen();
    $(".chzn-select").hide();
    

    Call hide immediately after initialization, don't know why this tricks works but it is doing what you want!

    I suggest you to use the latest version so you have access to latest options.

    Hope it works for you!

    0 讨论(0)
  • 2021-02-05 03:09

    Since none of the chosen-settings for hiding the search-field for multiple selects seemed to be working, I hacked the chosen.jquery.js in line 577 to:

    <li class="search-field"><span class="placeholder">' + this.default_text + '</span></li>
    

    (Span instead of the input field). Needed to comment out this line, too

    this.search_field[0].disabled = false;
    

    Working fine for me - even though its not the best practice to hack the code.

    0 讨论(0)
  • 2021-02-05 03:09
    disable_search:true,
    

    Here is the document for chosen jquery plugin

    0 讨论(0)
提交回复
热议问题