react-autosuggest icon indicating copy to clipboard operation
react-autosuggest copied to clipboard

Bug: Autosuggest throws an exception when value is 'number'

Open kavink opened this issue 7 years ago • 8 comments

For my form I need to pre-fill the value from server which end up as Integers.

But when I try to pass that to Autosuggest it fails, It does not have issues with String. Those work just fine

https://codepen.io/anon/pen/QQaxeP

Uncaught TypeError: (intermediate value)(intermediate value)(intermediate value).trim is not a function
    at Autosuggest.getQuery (Autosuggest.js:280)
    at Autosuggest.render (Autosuggest.js:497)
    at finishClassComponent (react-dom.development.js:7873)
    at updateClassComponent (react-dom.development.js:7850)
    at beginWork (react-dom.development.js:8225)
    at performUnitOfWork (react-dom.development.js:10224)
    at workLoop (react-dom.development.js:10288)
    at HTMLUnknownElement.callCallback (react-dom.development.js:542)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:581)
    at invokeGuardedCallback (react-dom.development.js:438)
    at renderRoot (react-dom.development.js:10366)
    at performWorkOnRoot (react-dom.development.js:11014)
    at performWork (react-dom.development.js:10967)
    at batchedUpdates (react-dom.development.js:11086)
    at batchedUpdates (react-dom.development.js:2330)
    at dispatchEvent (react-dom.development.js:3421)

kavink avatar Feb 17 '18 22:02 kavink

Yup, I encountered the same issue.

NicoleRauch avatar Mar 28 '18 20:03 NicoleRauch

@kavink @NicoleRauch Did either of you guys end up finding a way around this bug?

danarth avatar Aug 08 '18 11:08 danarth

Me too, got the same error.

paulogc avatar Aug 30 '18 16:08 paulogc

Seems like, the value parameter expects a string. Converting the value to a string using toString resolved the problem for me.

0004072 avatar Oct 01 '18 05:10 0004072

I have the same problem trying to work with Objects, I found a solution hacking the method GetQuery from the module: //Overide original method for internal use with object Autosuggest = function getQuery() { var inputProps = this.props.inputProps; var value = inputProps.value; var valueBeforeUpDown = this.state.valueBeforeUpDown; return value}

Basically I removed the trim at the end.

I basically need to override this method and it works. My problem is how

mirkourrunanos avatar Nov 14 '18 09:11 mirkourrunanos

So @mirkourrunanos did you figure it out how handle that?

matheuspoleza avatar Apr 12 '19 18:04 matheuspoleza

@matheuspoleza I got the same error and finally found out where I made an error : My onChange function (passed via the inputProps attribute) didn't destruct the newValue from the object :

onChange = (event, { newValue }) => {...}

instead of

onChange = (event, newValue) => {...}

By setting an object (containing the newValue attribute) instead of the string, it's impossible for AutoSuggest to call the trim method on it. Hope that helped !

bchoubert avatar May 07 '19 22:05 bchoubert

@matheuspoleza I got the same error and finally found out where I made an error : My onChange function (passed via the inputProps attribute) didn't destruct the newValue from the object :

onChange = (event, { newValue }) => {...}

instead of

onChange = (event, newValue) => {...}

By setting an object (containing the newValue attribute) instead of the string, it's impossible for AutoSuggest to call the trim method on it. Hope that helped !

In the onChange handler, I was using event.target.value to update my value. When I used the de-structured value of the second parameter (event, { newValue }), it worked. Thanks for this.

rvighnes avatar Nov 15 '20 03:11 rvighnes