Filtering Results

Nick's Avatar

Nick

25 Aug, 2010 08:46 AM

Let's say that you have a php script that, by querying a database, determines which elements are to be shown. However the pattern matching of the javascript does not work. So you would like an option to force the filtering of the results, or to avoid it. Here it is.

jQuery.autosuggest.js
____________________ 1) add an element to the options:
filterResults:false,

2) Line ~274
Change the if(str) block with this:
if(str){

**if (opts.filterResults) { // Check to see if the line should be filtered**
    if (!opts.matchCase){ str = str.toLowerCase(); }                
    if(str.search(query) != -1 && values_input.val().search(","+data[num][opts.selectedValuesProp]+",") == -1){
        forward = true;
    }
**} else {**
    **forward=true;**
**}**

}

If you set it to false, all lines will be shown in the drop down list. Otherwise, the script works as before.

I am a newbie in javascript, so sorry if this was obvious. Just trying to contribute my thing :)

  1. 1 Posted by Nick on 25 Aug, 2010 08:47 AM

    Nick's Avatar

    The code should be:

    if(str){

    if (opts.filterResults) { // Check to see if the line should be filtered
        if (!opts.matchCase){ str = str.toLowerCase(); }                
        if(str.search(query) != -1 && values_input.val().search(","+data[num][opts.selectedValuesProp]+",") == -1){
            forward = true;
        }
    } else {
        forward=true;
    }

    }

    The formatting was scr***d. Sorry for that.

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