0

Possible Duplicate:
jQuery Chosen reset

I'm using Chosen plugin on my project.

http://jsfiddle.net/tt13/gFzzc/

The problem is, I can't reset chosen input textbox programmaticaly. How to do it when I click clear button?

Community
  • 1
  • 1
heron
  • 3,611
  • 25
  • 80
  • 148

4 Answers4

2

First of all, you should use the correct version of Chosen, taken from here:

Then, simply reset the value of the select and trigger "liszt:updated" event:

$("button").on("click", function() {
    $(".chzn-select").val("").trigger("liszt:updated");
});​

DEMO: http://jsfiddle.net/gFzzc/13/

VisioN
  • 143,310
  • 32
  • 282
  • 281
2

This works jsfiddle

$('button').click(function(){
    $('.search-choice-close').click();
});

You might narrow down the scope a bit in case of multiple controls.

Fred
  • 5,663
  • 4
  • 45
  • 74
Jos
  • 419
  • 3
  • 12
0

You can try something like this :

Give Id to the button: say clear_chosen

and then trigger close button:

javascript code::

$("#clear_chosen").click(function(){
    $(".search-choice-close").click();
});

Write the code inside this block::

  $(function () {
    $('.chzn-select').chosen();
});
Anidhya Ahuja
  • 883
  • 7
  • 22
0

Ugly hack, but works:

Demo: jsfiddle

Code:

$('button').click(function() {
    $(".chzn-select").next('.chzn-container').find('.search-choice').remove();
    $(".chzn-select").val('');
    $(".chzn-select").next('.chzn-container').find('.search-field input').focus();
});
BomberMan
  • 1,094
  • 3
  • 13
  • 33
techfoobar
  • 65,616
  • 14
  • 114
  • 135