0

So here is my current js fiddle

http://jsfiddle.net/sbyLb93n/6/

I have tried adding

.replace(/\W*/mg, "")  

to wordsArr and valuesArr before I turn the string of text into an array of strings with .split(" ") (so right after i use .trim() on valuesArr and .toLowerCase() on wordsArr). should I iterate through the array after splitting and say 'for each arr in wordsArr, if arr has a character that isn't in a-z or 0-9, then remove that character and return this new string" ? if so, from where should i start to achieve this loop through the arrays? thanks dogs!

pbordeaux
  • 425
  • 1
  • 5
  • 18

1 Answers1

0

You do this using the filterCallback option of the filterable widget. Basically, override the default filter to compare the search text against the text with all punctuation stripped out:

<form class="ui-filterable">
    <input id="myFilter" data-type="search"></input>
</form>
<div class="elements" data-filter="true" data-input="#myFilter">
    <p class="parag">This is paragraph one or 1; it's not number 2</p>
    <p class="parag">Next is two too 2.</p>
    <p class="parag">Three 3! is after 2</p>
    <p class="parag">Finally is, 4 four but; 'not" two.</p>
</div>

$(document).on("pagecreate", "#page1", function()
    $(".elements").filterable('option', 'filterCallback', NoPunctuation);
});

function NoPunctuation( idx, searchValue ) {
    var ret = false;
    if (searchValue && searchValue.length > 0){ 
        var filttext = $(this).data("filtertext") || '';
        filttext = filttext.toLowerCase();

        var text = $(this).text().toLowerCase();            
        var punctRE = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#\$%&\(\)\*\+,\-\.\/:;<=>\?@\[\]\^_`\{\|\}~]/g;
var spaceRE = /\s+/g;
        text = text.replace(punctRE, '').replace(spaceRE, ' ');
        console.log(text);
        if( text.indexOf(searchValue.toLowerCase()) < 0 && filttext.indexOf(searchValue.toLowerCase()) < 0){
            ret = true; //filter this one out
        }
    } 
    return ret;
}

To strip punctuation, I used an answer from here: How can I strip all punctuation from a string in JavaScript using regex?

Community
  • 1
  • 1
ezanker
  • 24,628
  • 1
  • 20
  • 35