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] Add option to require a selection from the list #5494

Closed
djensen47 opened this issue Oct 31, 2016 · 5 comments
Closed

[AutoComplete] Add option to require a selection from the list #5494

djensen47 opened this issue Oct 31, 2016 · 5 comments
Labels
component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@djensen47
Copy link

djensen47 commented Oct 31, 2016

I'm using AutoComplete to ask a user to select one item from a very, very long list of options. However, the user is only allowed to select an item from the list an should not be able to enter free text. Part of the reason here is that the AutoComplete is searching on names and the value (an ID) is what is being saved behind the scenes.

Using and array of objects for dataSource in combination with dataSourceConfig gets me most of the way there. I think the best approach for the UI is if they dismiss the options (onBlur), then the searchText should be set back to blank, i.e., they did not choose a "valid" option.

In addition to the other much needed planned features for AutoComplete, I think it would be great to also include this functionality.

I could write a wrapper around AutoComplete to do this but that is going to be a fragile approach with a ton of pass through logic.

@djensen47
Copy link
Author

djensen47 commented Oct 31, 2016

In the meantime, my plan is the following

// this is PSUEDO-ish code
// 1. set initial state
this.setState({autocompleteValue: '', searchText: ''});
searchText={this.state.searchText};

// 2. use onNewRequest to set the value in state
onNewRequest={(chosen, index) => this.setState({autocompleteValue: chosen.value})}

// 3. clear autocompleteValue onUpdateInput

// 4. use onBlur to clear the search text if nothing was chosen
onBlur={(event)=> if (this.state.autocompleteValue == '') this.setState({searchText: ''})}

@Sharlaan
Copy link

Sharlaan commented Oct 31, 2016

Have you searched Issues with keyword "autoComplete" or "selectField" ? You may find some niceties ... ;)

@djensen47
Copy link
Author

I should have prefaced that I did do some searching but there are 209 results for "autocomplete." I read some of the threads on composition, which I kinda-sorta alluded to.

Not even sure how I should have known to search for "selectField" but thank you for the suggestion, I'll try it now. 😄

@CarsonF
Copy link
Contributor

CarsonF commented Dec 20, 2016

@djensen47 I needed something similar. Here's a gist of it. I tried to pull out all the business logic and removed typescript markup in the last 5 mins so it may need some tweaks.

@oliviertassinari
Copy link
Member

Closed by #4783

@oliviertassinari oliviertassinari added the component: autocomplete This is the name of the generic UI component, not the React module! label Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

4 participants