harvesthq/chosen — pull request #506 by abrimo (2012-02-25 04:53:26+00:00)
Title: Add callback when no results are found

Added an option to include a callback that is executed when no results are found. The option is 'no_results_callback(no_results_html_line,text)'. 'no_results_html_line' is the list item with the label saying 'no results found' and the 'text' is the entered text that could not be found.

This should enable you to do things like add a new option to the list when someone clicks on the 'not found' text. For example in jQuery:

```
$("#select").chosen({
no_results_text:
"We can't find that option, would you like to create: ",
no_results_callback: function(resultsHtml, terms) {
resultsHtml.css("cursor","pointer");
resultsHtml.click(function() {
$("#select").append($("
").attr("value",terms).text(terms));
$("#select").trigger("liszt:updated");
$("#select").focus();
});
}
});
```

N.B. you'll have to check on the prototype javascript as I'm not sure it's entirely correct.