Jitender
Jitender

Reputation: 7971

How to access function from plugin

I am using chosen jquery plugin for my select input. I want to reset select option on click on a tag so doing so I want to access jquery plugin function. DEMO

HTML

<select id="second" class="chzn-select" style="width:100px">
<option value="0"> select</option>
<option value="1"> mr</option>
<option value="2"> mrs</option>
</select>
<a href="#">reset</a>​

jquery

$(".chzn-select").chosen()
$('a').click(function(){
    $.chosen({results_reset})
})

​ function from plugin

Chosen.prototype.results_reset = function () {
    this.form_field.options[0].selected = true;
    this.selected_item.find("span").text(this.default_text);

    if (!this.is_multiple) this.selected_item.addClass("chzn-default");

    this.show_search_field_default();
    this.results_reset_cleanup();
    this.form_field_jq.trigger("change");

    if (this.active_field) return this.results_hide();
};

Here is the link for complete plugin http://harvesthq.github.com/chosen/chosen/chosen.jquery.js

Upvotes: 0

Views: 126

Answers (3)

Bhuwan Prasad Upadhyay
Bhuwan Prasad Upadhyay

Reputation: 3056

In Chosen Jquery

$('select-element').val('').trigger("chosen:updated");

NOTE: prior to 1.0 version used the following:

$('select-element').trigger("liszt:updated");

Upvotes: 0

Arun Manjhi
Arun Manjhi

Reputation: 173

You can try this also for resetting

$('a').click(function(){

     $('#second').trigger("liszt:updated");

})

Upvotes: 0

techfoobar
techfoobar

Reputation: 66663

Edit

To call a plugin function, you can do:

$('your-select').data('chosen').results_reset();

Demo: http://jsfiddle.net/vCE4Y/12/


You do not need to access plugin code to reset the select. You can reset it as follows:

$('your-select').val(0).trigger("liszt:updated");

Demo: http://jsfiddle.net/vCE4Y/11/

Upvotes: 1

Related Questions