Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback when no results are found #506

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions chosen/chosen.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,9 @@ Copyright (c) 2011 by Harvest
var no_results_html;
no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
no_results_html.find("span").first().html(terms);
if (this.options.no_results_callback) {
this.options.no_results_callback(no_results_html, terms);
}
return this.search_results.append(no_results_html);
};

Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions chosen/chosen.proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,9 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.no_results = function(terms) {
if (this.options.no_results_callback) {
this.options.no_results_callback(this.no_results_temp, terms);
}
return this.search_results.insert(this.no_results_temp.evaluate({
terms: terms
}));
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.proto.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ class Chosen extends AbstractChosen
no_results: (terms) ->
no_results_html = $('<li class="no-results">' + @results_none_found + ' "<span></span>"</li>')
no_results_html.find("span").first().html(terms)
if @options.no_results_callback
@options.no_results_callback(no_results_html, terms)

@search_results.append no_results_html

Expand Down
2 changes: 2 additions & 0 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ class Chosen extends AbstractChosen
this.result_do_highlight do_high if do_high?

no_results: (terms) ->
if @options.no_results_callback
@options.no_results_callback(@no_results_temp, terms)
@search_results.insert @no_results_temp.evaluate( terms: terms )

no_results_clear: ->
Expand Down