Conditional 'No Results Found' message

moonlight293's Avatar

moonlight293

14 Oct, 2012 08:19 PM

Hello once again.
This time it is less of an error and more of a desired functionality. Would it be possible to remove the 'No results found' message when a space bar has be pressed (and presumably nothing is in the list)? Of course, if the space character is removed then it can show up again.

Thank you!

  1. 1 Posted by Jon on 15 Oct, 2012 06:36 AM

    Jon's Avatar

    I don't know if this is what your are looking for but, try to change the first line of keyChange function from:

    if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) ){ return results_holder.hide(); }
    

    to

    if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) || lastKeyPressCode == 32 ){ return results_holder.hide(); }
    
  2. 2 Posted by moonlight293 on 15 Oct, 2012 08:27 PM

    moonlight293's Avatar

    Hi Jon,

    Not quite - essentially I want the autosuggest to stop once a space bar has been entered.
    In our auto suggest we want people to search for a phrase that may not be in the autosuggest list (since it's just a list of words), but not have the emptytext show when they decide to do that.
    e.g.
    For 'do' it should show a list of suggestions
    For 'dkasjhf' it should show emptytext
    For 'do the', 'do ' and 'do the wave' it should not show emptytext, even though none are in the autosuggest list.
    Does that make sense?

    After posting this question I managed to make a hacky solution.
    At around Line 349 I changed

       if (matchCount <= 0) {
                            results_ul.html('<li class="as-message">' + opts.emptyText + '</li>');
       }
    

    To become:

    if (matchCount <= 0 && query.indexOf(" ") == -1) {
                            results_ul.html('<li class="as-message">' + opts.emptyText + '</li>');
                        } else if (matchCount <= 0 && query.indexOf(" ") != -1) {
                            results_ul.hide();
                        } else {
                            results_ul.show();
                        }
    

    To ensure the autosuggest returned once the space was deleted I added this:

    case 8:  // delete - around line 162
                                results_ul.show();
    

    It seems to work fine, if not a bit hacky (especially with the delete). Is there a more elegant way to do this?
    Thanks again.

  3. 3 Posted by Jon on 16 Oct, 2012 10:20 AM

    Jon's Avatar

    Ok, I don't know any other way so if it works for you go ahead with it.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac