Wildcard matching

Caleb Hale's Avatar

Caleb Hale

12 May, 2010 04:00 PM

Hello,

Unless there is something I am missing, I couldent find a way to cinfigure your (otherwise amazing) plugin to do wildcard matching, or just a way to turn off the javascript searching when working with external data.

For example, in my data set is "Brighton folk club" and I wanted that to appear when I type "Brighton club". It would be great i you would add a config option for this.

I have achived this myself with the below modifactions (if they are any help)

Replaced
`

var forward = false;
if(opts.searchObjProps == "value") {
    var str = data[num].value;
} else {    
    var str = "";
    var names = opts.searchObjProps.split(",");
    for(var y=0;y<names.length;y++){
        var name = $.trim(names[y]);
        str = str+data[num][name]+" ";
    }
}
if(str){
    if (!opts.matchCase){ str = str.toLowerCase(); }                
    if(str.search(query) != -1 && values_input.val().search(","+data[num][opts.selectedValuesProp]+",") == -1){
        forward = true;
    }   
}`

With
var forward = false;

and
`

if (!opts.matchCase){ 
    var regx = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + query + ")(?![^<>]*>)(?![^&;]+;)", "gi");                         
} else {
    var regx = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + query + ")(?![^<>]*>)(?![^&;]+;)", "g");
}`

with
var regx = new RegExp('\\b('+$.trim(query).replace(' ','|')+')\\b', "gi");

My code could be a lot cleaner, but I hope it helps!

Thanks, Caleb

  1. 1 Posted by Caleb Hale on 12 May, 2010 04:03 PM

    Caleb Hale's Avatar

    Correction!

    var regx = new RegExp('(?![^&;]+;)(?!<[^<>]*)('+$.trim(query).replace(' ','|')+')(?![^<>]*>)(?![^&;]+;)', "gi");

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