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.

[Autocomplete] Provide more details in the onChange event

See original GitHub issue

Is there a way to get only the option that was added/removed in the onChange event handler? Controlled auto complete shows this as their onChange handler:

onChange={(event, newValue) => {
          setValue(newValue);
        }}

So when i use this for multiple my previous state is [A,B] and newValue is [A,B,C]. I have to diff the previous state with next state to see what was added or removed. When I tried using event.target.value, the first onChange returns 0 then after gives me the correct value that changed.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
whuey1992commented, Jan 3, 2020

When a new option is selected I can check the last element added to newValue but for deletion I need to do a diff of previous state vs newValue. Which is also kind of made more difficult to distinguish for clear

0reactions
netochavescommented, Jan 19, 2020

If you guys don’t mind i’ll work on that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use onchange with autocomplete material ui?
The handleChange function in turn calls setLocation which updates the location state with the new value. To make user data entry easier, I ......
Read more >
[Autocomplete] Provide more details in the onChange event
I am using two autocompletes for a form. When certain options are selected in one autocomplete, it requires options from the other autocomplete...
Read more >
Change Event on autocomplete - Material Design for Bootstrap
Hi, the change event on autocomplete triggers before the value is actually changed, thus .val() still gives the old value.
Read more >
React Autocomplete component - Material UI - MUI
The component has two states that can be controlled: the "value" state with the value / onChange props combination. This state represents the...
Read more >
Autocomplete Widget - jQuery UI API Documentation
Description : Autocomplete enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering....
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