jQuery Chosen plugin without search field

2019-03-14 07:39发布

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 jQuery chosen plugin (used to style select inputs). Specifically I'd like to use the standard select one without it.

http://harvesthq.github.com/chosen/

12条回答
beautiful°
2楼-- · 2019-03-14 07:53
$('select').chosen( {disable_search: true} );
查看更多
Deceive 欺骗
3楼-- · 2019-03-14 07:56

Well I tried with the documentation as well and no luck, so I finally fixed to this

$('.chzn-search').hide();

I do the above after I call chosen. Hope this helps

查看更多
神经病院院长
4楼-- · 2019-03-14 07:56

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.

查看更多
女痞
5楼-- · 2019-03-14 07:58

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

$('ul.chosen-choices li.search-field').hide();
查看更多
We Are One
6楼-- · 2019-03-14 08:02
$(".chzn-select").chosen({disable_search_threshold: 3});

If the number of element of the select is smaller than disable_search_threshold (here 2 and less), the search box will not display.

查看更多
ら.Afraid
7楼-- · 2019-03-14 08:06

Just a quick follow-up: I noticed that in function

AbstractChosen.prototype.set_default_values

a variable is read from

this.options.disable_search

So you can disable the search-field with

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

without using a fixed-number threshold.

查看更多
登录 后发表回答