Autocomplete - Changing Input programatically
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
I am changing the input of the Autocomplete programatically in the following way:
- I get a reference of the TextField component inside the Autocomplete
- I create a new Event for changing it’s value with the following code:
const input = inputRef.querySelector('input') // get the referece of the input
var valueSetter = Object.getOwnPropertyDescriptor(input,'value').set
const prototype = Object.getPrototypeOf(input)
const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype,'value').set
if (valueSetter && valueSetter !== prototypeValueSetter) {
prototypeValueSetter.call(input, lastComment.updatetype.toString());
} else {
valueSetter.call(input, lastComment.updatetype);
}
input.dispatchEvent(new Event('input',{bubbles:true})) // dispatch the event to trigger the onChange method
- After that code executes, the TextField will talk to an API to render possible entries for the Autocomplete. And this works fine, I see the TextField changing and the Autocomplete giving me the possible list of items from the API based on the TextField value
- However, when I select the option from the Autocomplete, the onInputChange method doesn’t fire, and the selected option is never recorded
Expected Behavior 🤔
After selecting the option rendered on the Autocomplete, the onInputChange method has to trigger so the selected option can be saved to state
Context 🔦
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v4.9.4 |
React | 16.12.0 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Autocomplete - Changing Input programatically · Issue # ...
I get a reference of the TextField component inside the Autocomplete; I create a new Event for changing it's value with the following...
Read more >Programmatically set value in material-ui Autocomplete ...
Question: how can I programmaticaly set an input value by clicking on the button without choosing from the dropdown list? For example, I...
Read more >How to Disable the Browser Autocomplete and Autofill on ...
Learn how to prevent browsers auto filling the input fields of HTML forms. Use autocomplete="off" to specify that autocomplete is disabled. See examples....
Read more >Technique H98:Using HTML 5.2 autocomplete attributes
The technique works by adding the appropriate autocomplete token to each form field on the form to make the identified inputs Programmatically Determinable....
Read more >Place Autocomplete | Maps JavaScript API
The Autocomplete widget creates a text input field on your web page, supplies predictions of places in a UI pick ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@erfansamieyan, I get what you’re saying but the issue is that onChange on the Textfield does not get triggered. You can see this example in this Codesandbox. This is how I finally solved my issue
The onChange callback will fire if called properly.