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

JS Error using numbers in query #881

Closed
MUTOgen opened this issue Jul 3, 2014 · 11 comments
Closed

JS Error using numbers in query #881

MUTOgen opened this issue Jul 3, 2014 · 11 comments
Milestone

Comments

@MUTOgen
Copy link

MUTOgen commented Jul 3, 2014

I'm using typeahead.js 0.10.2
If i have a field with numbers to autocomplete i have strange problem.

First time it's ok. I input numbers, suggestions shown, i select something from dropdown.
But if i remove everything in the field and try to type again, i have error in console and no dropdown shown.

Uncaught TypeError: undefined is not a function typeahead.bundle.js:944
Input.normalizeQuery typeahead.bundle.js:944
areQueriesEquivalent typeahead.bundle.js:1091
checkInputValue typeahead.bundle.js:998
onInput typeahead.bundle.js:962
proxy jquery.js:513
jQuery.event.dispatch jquery.js:4409
elemData.handle
@jharding
Copy link
Contributor

jharding commented Jul 8, 2014

I'm having trouble reproducing this, would it be possible for you to create a jsbin?

@jharding jharding added this to the v0.10.3 milestone Jul 8, 2014
@MUTOgen
Copy link
Author

MUTOgen commented Jul 9, 2014

i fix this here

Input.normalizeQuery = function(str) {
            str = str.toString(); // typecast if str contains only numbers, like "123"
            return (str || "").replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
        };

@jharding
Copy link
Contributor

jharding commented Jul 9, 2014

Do you ever call jQuery#typeahead('val', myVal) to set the value of the input? I'm wondering how a non-string is getting to the normalizeQuery function.

@MUTOgen
Copy link
Author

MUTOgen commented Jul 9, 2014

Yes, i call it
In my case autocomplete action on select event fills other typeahead fields with jQuery#typeahead('val', myVal)
I do it by ajax call

@jharding
Copy link
Contributor

jharding commented Jul 9, 2014

Ah, ok. My guess as to what's going on is that you pass a number to jQuery#typeahead('val', myVal) and right now, that's not handled very well. What I'm going to do is coerce everything passed to that method into a string. That should result in the expected behavior.

jharding pushed a commit that referenced this issue Jul 9, 2014
@jharding
Copy link
Contributor

jharding commented Jul 9, 2014

Added a fix for v0.10.3. Thanks for helping me debug.

@HenryYan2012
Copy link

Still have this issue on v0.10.5.

@kanejoe
Copy link

kanejoe commented Sep 13, 2014

also here on v0.10.5 with the following message:

Uncaught TypeError: undefined is not a function typeahead.bundle.js:998
c.normalizeQuery typeahead.bundle.js:998
e typeahead.bundle.js:1146
b.mixin._checkInputValue typeahead.bundle.js:1052
b.mixin._onInput typeahead.bundle.js:1016
_.isFunction.e jquery.js:513
_.event.dispatch jquery.js:4409
q.handle jquery.js:4095

@s01ipsist
Copy link

I also got this on v0.10.5 but was able to trace it to the fact that my data source was returning a single length array of strings. e.g.

[{"value":["Blood"]},{"value":["Blame"]}]

The normalizeQuery function errors when passed an array as you can't call replace on it.

Fixing my data source to this resolved my problem

[{"value":"Blood"},{"value":"Blame"}]

Perhaps this.query should be coerced to a string when it is saved?

@deancsmith
Copy link

I was having the same issue in v0.10.5 and resolved it by casting the 'caseNumber' property in the below picture from an int to a string before it is output as JSON to Typeahead. This property is my displayKey if that helps.

image

@DUAB-Johan
Copy link

I can verify deancsmith solution. I also had an int, and changing that to a string solved it. Using v0.10.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

7 participants