jquery-chosen

Changing selection in a select with the Chosen plugin

北城以北 提交于 2019-11-28 17:20:58
I'm trying to change the currently selected option in a select with the Chosen plugin. The documentation covers updating the list, and triggering an event when an option is selected, but nothing (that I can see) on externally changing the currently selected value. I have made a jsFiddle to demonstrate the code and my attempted ways of changing the selection: $('button').click(function() { $('select').val(2); $('select').chosen().val(2); $('select').chosen().select(2); }); Lucas Welper From the "Updating Chosen Dynamically" section in the docs : You need to trigger the 'chosen:updated' event on

allow new values with chosen.js multiple select

↘锁芯ラ 提交于 2019-11-28 16:20:00
I'm using the chosen.js plugin http://harvesthq.github.com/chosen/ with jQuery to allow the user to select multiple options from a select. However, I now want to be able to let them create values that aren't already present - any idea how to go about this? EDIT: something similar to SO's own tag selection/creation bar would be close to what I'm after Preferably without changing or editing the plugin, but will do if required. The code: HTML: <p>Select something</p> <select name="theSelect[]" multiple="multiple"> <option value="First Option">First Option</option> <option value="Second Option"

What are the differences between Chosen and Select2?

[亡魂溺海] 提交于 2019-11-28 15:08:39
Chosen and Select2 are the two more popular libraries for extending selectboxes. Both seem to be actively maintained, Chosen is older and supports both jQuery and Prototype. Select2 is jQuery only, its documentation says Select2 is inspired by Chosen, but doesn't detail any improvements made (if any) or other reasons for the rewrite. Two libraries have pretty much same feature set, the only comparison I've found is a somewhat inconclusive jsperf test page. Does any of these libraries have any advantages over the other? As of Select2 3.3.1, below are what's documented in its README.md What Does

Not getting validation message for @Html.DropDownListFor() once Chosen jquery is used

拜拜、爱过 提交于 2019-11-28 13:54:29
Code is given below: If i do not select any value in the combobox and press submit, no validation message is asked. <tr> <td>Department </td> <td> : </td> <td class="@*@Model.NoEdit*@"> @Html.DropDownListFor(m => m.DepartmentId, new SelectList(Model.Departments, "SelectedDepartmentId", "DepartmentCode"), "-- Select Department--", new {@class = "chosen-select", id = "cboDeptartment" }) @Html.ValidationMessageFor(model => model.DepartmentId) </td> Restating my brief comment as an answer. :-) To get the validation messages, I use the same approach Joseph mentions, though I use an HTML class for

jQuery Chosen plugin add options dynamically

混江龙づ霸主 提交于 2019-11-28 06:42:10
I make a jQuery Chosen drop-down like this: $('.blah').chosen(); I can't find how I can add options, something like: $('.blah').chosen('add', name, value); First, you need to add the <option> s to the <select> that Chosen was bound to. For example: $('.blah').append('<option value="foo">Bar</option>'); Then, you need to trigger the chosen:updated event: $('.blah').trigger("chosen:updated"); More information can be found here (although you need to scroll down to Change / Update Events ). Update 7th August 2013 The event name has changed to chosen:updated since version 1.0 (July 2013) as Tony

chosen with bootstrap 3 not working properly

白昼怎懂夜的黑 提交于 2019-11-28 04:55:53
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. Here's the code: $('.someClick').click(function(e){ e.preventDefault(); x.modal('show'); x.find('.modal-body').load('path/page.html', function(response, status, xhr){ if(status =="success") $("select[name=elementName]").chosen(); }); }); the results I'm getting is like the following image: and this is my Html content: <select name="elementName" data-placeholder="Please work.." class="chosen-select"> <option value="test">Hi</option> <option

jQuery Chosen reset

倖福魔咒の 提交于 2019-11-28 03:53:15
I have a bunch of select elements in a form with which I am using the Jquery Chosen plugin . How can I reset the form? The following does not work: <input type="reset" /> sottenad You'll need to reset the value of the field, then trigger the liszt:updated event on the input to get it to update, ive made a fiddle with a working example here. http://jsfiddle.net/VSpa3/3/ $(".chzn-select").chosen(); $('a').click(function(){ $(".chzn-select").val('').trigger("liszt:updated"); });​ Since the release of chosen v1.0 the trigger is now called 'chosen:updated'. Anyone using this new version needs to

Jquery Chosen plugin - dynamically populate list by Ajax

对着背影说爱祢 提交于 2019-11-28 03:40:34
Im trying to build my dropdown menu using the plugin Chosen for Multiple Select . Here's to behavior I'm based on: http://jsfiddle.net/JfLvA/ So, instead of having 3 harcoded < option > in my select. I want this list to be the values of a json array populated by an ajax request. This will be triggered by autocomplete. So, if the user type "car", im sending the letter via an ajax call, and im getting back an array like that: [{"id":"2489","name":"carrie"},{"id":"2490","name":"Caroline"},{"id":"2491","name":"Carole"}] The code: $(function() { $(".chzn-select").chosen(); $(".chzn-select-deselect"

How to add Chosen Plugin to dynamically created / cloned CSS div?

冷暖自知 提交于 2019-11-27 16:15:35
The Chosen Plugin for jQuery (found here: http://harvesthq.github.com/chosen/ ) adds extra functionality to select HTML elements. I can add the functionality to the initial elements loaded on the page with the following code: $(document).ready(function(){ $(".chosenProperties").data("placeholder","Select properties...").chosen(); $(".chosenType").data("placeholder","Type...").chosen(); $(".chosenInstance").data("placeholder","Instance...").chosen() That works. All three of those classes of select elements appear in a div called #newGroup. There is a button the page that "adds" a new group,

Not getting validation message for @Html.DropDownListFor() once Chosen jquery is used

巧了我就是萌 提交于 2019-11-27 08:09:14
问题 Code is given below: If i do not select any value in the combobox and press submit, no validation message is asked. <tr> <td>Department </td> <td> : </td> <td class="@*@Model.NoEdit*@"> @Html.DropDownListFor(m => m.DepartmentId, new SelectList(Model.Departments, "SelectedDepartmentId", "DepartmentCode"), "-- Select Department--", new {@class = "chosen-select", id = "cboDeptartment" }) @Html.ValidationMessageFor(model => model.DepartmentId) </td> 回答1: Restating my brief comment as an answer. :