Add callback when no results are found #506

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

abrimo commented Feb 25, 2012

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($("<option selected></option>").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.

Callback function for when no results are found
Added an option to include a callback that is executed when not 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.
Member

koenpunt commented Mar 14, 2012

Perhaps you should take a look at my pull request: #166

Contributor

pfiller commented May 26, 2012

Thanks @abrimo

I'm sorry it took so long to review this. There are several other pull requests that address adding new options and I wanted to give them all a fair shake. To my eyes, it looks as though #166 and #320 are more complete options so I'm going to focus on those. Feel free to weigh in on those threads.

@pfiller pfiller closed this May 26, 2012

abrimo commented May 28, 2012

Cool thanks, the other solutions look good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment