Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reset a form with jQuery chosen plugin?

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" /> 
like image 379
P H Avatar asked Oct 26 '11 01:10

P H


People also ask

What is chosen in jQuery?

Chosen is a JavaScript plugin that makes select boxes user-friendly. It is currently available in both jQuery and Prototype flavors.


2 Answers

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 trigger the update using

$(".chosen-select").val('').trigger("chosen:updated"); 
like image 144
sottenad Avatar answered Sep 23 '22 06:09

sottenad


Since the release of chosen v1.0 the trigger is now called 'chosen:updated'. Anyone using this new version needs to trigger the update using

$(".chosen-select").val('').trigger("chosen:updated"); 
like image 32
Jack O'Neill Avatar answered Sep 19 '22 06:09

Jack O'Neill