Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match doesn't work with numbers #207

Open
leomleao opened this issue May 20, 2016 · 2 comments
Open

match doesn't work with numbers #207

leomleao opened this issue May 20, 2016 · 2 comments

Comments

@leomleao
Copy link

So I needed a autocomplete to an input with only numbers.
Since the data that i have is a huge list I needed the match enabled.
But since the input was only numbers the function .search was not working properly.

As a turn around for this I changed the match method to this:

method: function(element, phrase) {
var elm = element + '';
if (elm.search(phrase) > -1) {
return true;
} else {
return false;
}

                }

I'm sure tho, that there is a better way to avoid the issue.

The error i was getting is:

Uncaught TypeError: element.search is not a function

@leomleao
Copy link
Author

This looks a lil better.
I'm new to GitHub, but this could be a nice addiction to the source in future releases

`method: function(element, phrase )
{
if (!isNaN(element) ? element.toString().search(phrase) > -1: element.search(phrase) > -1 )
{
return true;
} else {
return false;
}

                }`

@marsjaninzmarsa
Copy link

When you call toString() on string you'll still get string, so there is no need to type check. 🙂

marsjaninzmarsa added a commit to marsjaninzmarsa/EasyAutocomplete that referenced this issue Oct 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants