question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select.Async with Promise - Shows "[object, object]" in input field when doing a search

See original GitHub issue

This is my Select.Async code: <Select.Async name="code-chooser" valueKey="codeid" labelKey="codeDescription" value={this.state.chosenCode} loadOptions={this.getCodes} onChange={(code) => {this.setChosenCode(code)}} onInputChange={(value) => { return ""; }} placeholder="Select code..." ignoreCase={ true } clearable={ true } searchable={ true } />

My option object looks like this: {codeid: "<ID>", codeDescription: "<description>", codeLongDescription: "<long description>"}

As you can see in the onInputChange attribute I just return “”. When I have it like this everything works, but if I instead return the value or if I remove the whole “onInputChange” the input field dosn’t work anymore. As soon as I try to search, the input field just displays “[object, object]”. I also notice that every time I press a key the getCodes-function runs.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:13
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Frezzaldocommented, Jun 15, 2016

I ended up with the following configuration:

<Select.Async
                name="code-search"
                valueKey="codeid"
                labelKey="codeDescription"
                value={this.state.chosenCodeType}
                loadOptions={this.getCodeTypes}
                onChange={(codeType) => {this.setChosenCodeType(codeType);}}
                onInputChange={() => { return ""; }}
                optionRenderer={this.renderOption}
                filterOption={this.filterCodeType}
                ignoreCase={true}
                clearable={true}
                searchable={true}
                multi={false}
 />

The two most important settings are onInputChange and filterOption. Returning only “” in the onInputChange method prevent the getCodeTypes to run every time you press a key. Then in the filterOption (runs on each element in en dropdown) you return true or false if the element should display or not. This is how my filter-method looks like:

filterCodeType(option, filter) {
        const {codeid, codeDescription, codeLongDescription} = option;
        const filterWords = filter.trim().split(' ');

        for(let i in filterWords ) {
            const fWord= filterWords[i];
            if (fWord!= codeid && codeDescription.toLowerCase().indexOf(fWord) == -1 && codeLongDescription.toLowerCase().indexOf(fWord) == -1) {
                return false;
            }
        }
        return true;
    }

This worked for me @jsartisan @diegoconcha .

0reactions
bladeycommented, May 27, 2020

Hello -

In an effort to sustain the react-select project going forward, we’re closing old issues / pull requests.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.

If you feel this issue / pull request is still relevant and you’d like us to review it, please leave a comment and we’ll do our best to get back to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2 - Displaying async Object data from promise
I've created a StockService class that returns a Promise containing an object to my StockInfo class, which contains the HTML to be displayed....
Read more >
How to use promises - Learn web development | MDN
A promise is an object returned by an asynchronous function, which represents the current state of the operation. At the time the promise...
Read more >
How to access object properties from result returned by async ...
In this article, we will see how to access the properties of a javascript object result returned by the async() function in Javascript....
Read more >
Understanding the Event Loop, Callbacks, Promises, and ...
A promise represents the completion of an asynchronous function. It is an object that might return a value in the future. It accomplishes...
Read more >
Why am I getting [object Promise] when calling async function ...
You are getting [object Promise] as value because you are calling an asynchronous function inside a synchronous code. This means the synchronous ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found