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

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

Open Frezzaldo opened this issue 10 years ago • 16 comments

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.

Frezzaldo avatar Jun 03 '16 11:06 Frezzaldo

same is happening with me.

@Frezzaldo any solution?

jsartisan avatar Jun 12 '16 04:06 jsartisan

Same here. Any lock @jsartisan or @Frezzaldo?

diegoconcha avatar Jun 12 '16 15:06 diegoconcha

@diegoconcha since async select was not working. I used simple select. i had to sent all the data to the component before rendering.

jsartisan avatar Jun 13 '16 06:06 jsartisan

Makes sense. My dataset is too big so I need to be able to only show a fraction at a time based on the input. Thanks and hopefully this gets resolved soon.

diegoconcha avatar Jun 13 '16 12:06 diegoconcha

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 .

Frezzaldo avatar Jun 14 '16 08:06 Frezzaldo

Ran into same issue. @Frezzaldo's solution worked for me.

joshparolin avatar Jun 17 '16 23:06 joshparolin

I have the same issue and I have tried @Frezzaldo solution and it didn't work for me React select version: react-select: "^1.0.0-beta13" here is my code

<Select.Async
                cache={false}
                name={field.name}
                value={field.value || ''}
                {...field}
                loadOptions={fieldInfo.loadOptions}
                onBlur={() => {}}
                onChange={(ev) => { field.onChange(ev) }}
                {...parentValue}
                {...field.options}
                onInputChange={() => { return ""; }}
                clearable={true}
                searchable={true}
                multi={true}
                matchPos="any"
                matchProp="label"
                ignoreCase={true}
            />

Iliyass avatar Jul 01 '16 13:07 Iliyass

@Iliyass you don't use the filterOption-property. Maybe that will solve your problem.

Frezzaldo avatar Jul 01 '16 15:07 Frezzaldo

@Frezzaldo I did tried it, and it didn't solve the issue :(

Iliyass avatar Jul 01 '16 18:07 Iliyass

I'm having the same problem here. For now I chose to preload all my options as the list will not be very long anyways, but I am keen on finding a solution for some other use cases.

webloem avatar Jul 07 '16 08:07 webloem

same issue

terion-labs avatar Jul 08 '16 16:07 terion-labs

also experiencing this

rudeayelo avatar Jul 22 '16 13:07 rudeayelo

FYI - upgrading to v1.0.0-beta14 fixed this for me.

joshparolin avatar Aug 10 '16 07:08 joshparolin

Thanks @joshparolin for the heads up!

diegoconcha avatar Aug 10 '16 12:08 diegoconcha

@joshparolin Updating to beta14 did the trick for me also!

tsteele2013 avatar Aug 18 '16 15:08 tsteele2013

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.

bladey avatar May 27 '20 06:05 bladey