mattyork / fuzzy

Filters a list based on a fuzzy string search
MIT License
831 stars 86 forks source link

undefined is not a function (evaluating 'str.toLowerCase()') #28

Closed justinireland closed 8 years ago

justinireland commented 8 years ago

I'm reopening a new issue relating to issue #27 since it was closed prematurely.

mattyork commented 8 years ago

All javascript strings should have the toLowerCase() method. Maybe React Native wraps string inputs in some other object? Does calling toString() on the input string fix the problem? i.e. fuzzy.filter(stringInput.toString(), list). I can't reproduce this in a non React Native environment and I don't plan to set up a React Native environment, but will happily make a fix if we find one.

justinireland commented 8 years ago

toString() makes no difference and I can confirm that the input is typeof string.

justinireland commented 8 years ago

Also, I am searching an array of objects (with only text fields) if that makes any difference.

mattyork commented 8 years ago

@justinireland what exactly do you mean by an array of objects with only text fields?

If your array is like this:

var arr = [{textField: 'a'}, {textField: 'b'}]

Then fuzzy won't know to extract textField from each object unless you tell it to:

fuzzy.filter('a', arr, { extract: obj => obj.textField });
justinireland commented 8 years ago

Ok, that was part of the problem. I was not properly extracting the field I needed from the array objects.