-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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] The value provided to Autocomplete is invalid. (with the installed isOptionEqualToValue) #29727
Comments
Could you please create a codesandbox highlighting the problem? You can use the following template: https://mui.com/r/issue-template |
Sure Also another problem, if i set the startAdornment like an icon, then the selected options are not shown |
Sorry for the late response. I'm getting a 404 error on the sandbox you provided. Could you check it? |
I have this issue as well, and I think its the same case. It can happen when implementing an external async search. The Autocomplete component still has a value, but the options are now populated with the results from the search, which does not include the current value. Here is a reproduction: https://codesandbox.io/s/asynchronous-material-demo-forked-q0yox?file=/demo.tsx Steps to repro:
It doesn't repro 100% of the time, but its pretty easy to get it to happen. |
@mbrookes can this be reopened? |
Thanks for the reproduction, @markedwards. I'm reopening the issue. |
I'm experiencing this problem too. Great to see that this issue is opened! |
Also ran into this issue while fetching autocomplete options from the Google Maps Places API and my own backend. I tried to work around the issue by clearing out the Open to suggestions for other ways to avoid the warning or if it's okay to just to ignore it overall. |
Could we please get an option to turn off the warning completely? At this stage it's causing a lot of noise in tests and, as reported, it's not warning anything useful. |
I have the same Issue ... boring warning |
Apparently, at this point, the warning causes more confusion than assistance. If anyone is willing to investigate if this warning can be disabled for cases of async loading without much hassle, then feel free to grab this issue. I'm also considering removing the warning altogether, but let's try the less destructive option first. |
In case anyone stumbles upon this issue today still, the trick for async-populated options is to add the currently selected option so that it doesn't trigger the false positive that can happen when setting a new value while an async request changes the array of options that is provided. const [item, setItem] = useState<ItemModel>();
const [items, setItems] = useState<ItemModel[]>([]);
const [input, setInput] = useState('');
const query = useDebounce(input, 250);
useEffect(() => {
fetchItems(query).then((items) => setItems(items));
}, [query]);
return (
<Autocomplete
autoComplete
filterSelectedOptions
getOptionLabel={(option) => option.name}
onInputChange={(_event, value) => setInput(value)}
onChange={(_event, value) => setItem(value)}
options={item ? [item, ...items] : items}
renderInput={(extra) => <TextField {...extra} label="Name" />}
/>
); |
still an issue for me. not wanting to add more state as said in @angrybacon answer, because i use react hook form mainly to control the state. <Controller
name={"district"}
control={control}
render={({ field: { onChange, value } }) => (
<Autocomplete
onChange={(e, data) => onChange(data)}
options={districts.map(({ id, name }) => ({ id, name }))}
value={value}
getOptionLabel={(option) => option.name}
isOptionEqualToValue={(option, newValue) => {
return option.id === newValue.id;
}}
renderInput={(params) => (
<TextField {...params} placeholder="test" label="test" />
)}
onInputChange={(_evt, newValue) => setSearch(newValue)}
inputValue={search}
/>
)}
/> can i just return true for |
I'm currently struggling with this. I'm going to use this comment box as a rubber duck and maybe someone can explain what I'm doing wrong. So... This error has made me realize I don't entirely get what the point of the From what I can see, the both the text input and the selection set the I've been storing my value in a hook, and passing it back in to both
The latter I suppose can be mitigated by unsetting the "select value" when the user modifies the input text and falling back to So, am I doing something wrong or is this warning truly just meaningless? I feel like I must be doing something wrong because surely the I think for now I will just use a As a closing note, if my intuitions are correct, I'd argue the naming of the Thoughts? |
I forked the controlled input example from the documentation and tweaked it slightly, working towards what I was actually building (albeit not for Harry Potter characters). Although the warning does not show up, there is a lot of questionable UX going on. You will notice the behavior where you delete half the name and it reappears on blur because of the odd implementation choice of having the I've "solved" that by setting Of course, creating this dummy value object does make it clear why the warning shows up. Which would bring me back to: Either the Autocomplete component should be completely re-thought (probably the "right" solution) w.r.t. multiple values and setters, OR the warning should be ditched and you can set the value to whatever you want. The latter also does feel like a "right" choice considering entering non-specific options is kind of the whole thing that sets |
Got same issue. Too bad there's no solution yet, but glad that it's on the radar. |
I had a bit different kind of a problem that is described in this thread, but as it lands on same field I decided to post here rather to post new thread (hope that's fine). TL;DRA opinion that has very minor affect on... anything. May resolve some common issues found in internet with this component. DecriptionI have MUIv5 and I use MUI Autocomplete, with Formik (with Yup) and use typescript. I've come into an opinion where I feel like that useAutocomplete ( By the snipped code below, it states that the Autocomplete initial value can not be In my case this caused the form to be initialized with "undefined"... string (what the ...) and bunch of error/warning messages, saying:
Curtain callI resolved my problem by initializing form values with null and applying Sample code:
|
Is there any update on this? Still able to reproduce this issue locally. @michaldudak |
For anyone who may still be running into this warning. The issue I ran into was a mislabelling of "freeSolo", with a capital "S". |
I have multi select
Happy coding :) |
While Perhaps there should be a prop to signify "Search as you type" (as the Docs refers to it) that does not allow for free entry but does allow for items to exist in the values that don't exist in the current options and, by default, disables |
@michaldudak I added PR with |
Hi all. Is there an update on this issue? I agree 200% with @derekcannon , as I am using multi-select autocomplete with queried options upon keyboard input. So the selected options may not be on the current options, as the options are queried upon input and dynamic. Everything works fine, but I would love to suppress the Warning... |
Any updates on this? Looks like this suggestion could allow fixing the issue. |
I can't say I like the idea of introducing yet another prop to the Autocomplete, especially just for suppressing a warning. @DiegoAndai, @mj12albert, @mnajdova, I propose to remove the warning altogether. |
@michaldudak I agree that we should suppress the warning. |
I agree with suppressing this warning. In my use case, I have one HTTP GET request to get my full object, and then map each value to the form as needed (as a view form, that can be edited). The Autocomplete is populated when the user types, in this case I have to handle it to avoid the warning, but it wouldn't really be necessary, options will be populated as soon as the user interacts with the autocomplete (including the initial option), so in summary it would be nice to not deal with the warning at all for these cases. |
We agree regarding suppressing the warning and adding a warning in the docs, so I'll add the cc: @mnajdova |
I am new to the repo, I would love to contribute, and I will read the contribution.md. Just wondering, is to surppress the warning is to delete the Edit: nvm, I just noticed the open pr |
I came across this as I was trying to resolve this issue myself. I was able to get this warning removed by providing a const value = field.value || null;
<Autocomplete
value={value}
...
/> I'm still on MUI 5 but wanted to share in case this works for the latest versions |
I am using typescript and this had worked for me: <Autocomplete
//freeSolo
id="size-small-outlined"
size="small"
className="flex-1"
options={seletorLoteOrcamento}
isOptionEqualToValue={(option, selectedValue) => option.value === selectedValue.value} // <- you also need to add this code
onChange={(event, newValue) => {
const labelValueSelecionado = newValue as ILabelValue; // <- I just typed the value and it worked
lidarOrcamentoSelecionado(Number(labelValueSelecionado?.value));
}}
renderInput={(params) => <TextField {...params} label="Orçamento" />}
/> I hope it works for you too. |
Any updates ? I'm encountering the same issue with latest Mui even without Multiple activated :
|
@mnajdova given that this issue is getting activity consistently, I think we should remove the warning for v6. What do you think? |
saved my life! ❤️ |
Created PR to remove the warning: #43314 |
SAVED MY LIVE TOO |
Duplicates
Latest version
Current behavior 😯
I get an «value provided to Autocomplete is invalid» error:
Expected behavior 🤔
Well, if i use the
isOptionEqualToValue={(option, value) => option.id === value.id}
, the expected behavior is that I shouldn't get an error.Steps to reproduce 🕹
Steps:
Context 🔦
No response
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: