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

[Autocomplete-Select] Keep all data in options, and allow to retrieve them in onChange #1448

Open
rodolpheV opened this issue Sep 15, 2017 · 4 comments · May be fixed by #1466
Open

[Autocomplete-Select] Keep all data in options, and allow to retrieve them in onChange #1448

rodolpheV opened this issue Sep 15, 2017 · 4 comments · May be fixed by #1466
Assignees

Comments

@rodolpheV
Copy link
Contributor

Current behaviour

The autocomplete select component only keep label and value properties in its options:
edit.js#L153: data.forEach(item => { options.set(item[keyName], item[labelName]); });
And only the key is given to the onChange:
edit.js#L210: onChange(key)

As others data properties are only in the store used by the querySearcher, the view has to directly get them here if needed.

Expected behaviour

Keep all data in options: this.setState({options: data}), or keep them duplicated in data: this.setState({data})
And allow to retrieve them in onChange: onChange(key, option)

Versions

Focus-core: 2.1.1
Focus-components: 2.1.7-1

@Hartorn Hartorn self-assigned this Sep 15, 2017
@Hartorn
Copy link
Contributor

Hartorn commented Sep 15, 2017

@rodolpheV I won't add a second argument on onChange function.
For input, onChange should take only the value on entry.
Eventually, we could have an option to get the whole value instead of the key.

But before that, for your problem, I don't see any use case. Could you elaborate a bit more ?

@rodolpheV
Copy link
Contributor Author

Then I'll explain my use of this component:
I have a component that uses the AutocompleteSelect to get a unit:

<AutocompleteSelect
   querySearcher={this.searchUnit}
   onChange={this.onUnitOptionClick}
   keyName='unitId'
   labelName='value'
/>

The method onUnitOptionClick passed as onChange to the AutocompleteSelect:

onUnitOptionClick(unitId) {
    const storeUnitList = planStore.searchUnit();
    const unit = storeUnitList.find(u => u.unitId === unitId);
    return this.addUnitToSelection(unit);
},

And I would like to do:

onUnitOptionClick(unitId, unit) {
    return this.addUnitToSelection(unit);
},

@Hartorn
Copy link
Contributor

Hartorn commented Sep 26, 2017

I guess we can add on option wholeValue, and in onChange, return the whole value instead of the id in this case.

@Hartorn Hartorn assigned c3dr0x and unassigned Hartorn Sep 26, 2017
@Hartorn
Copy link
Contributor

Hartorn commented Sep 26, 2017

@c3dr0x I let you do that one :)

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

Successfully merging a pull request may close this issue.

3 participants