MUI:提供给自动完成的值无效。这些选项都与``''''''
当在自动完成组件的输入中输入一个值时,我会收到此警告,我无法删除... 这就是我的输入看起来,
<Autocomplete
id="cboAdresse"
sx={{ width: 100 + "%", fontFamily: "Poppins Bold" }}
getOptionLabel={(option) =>
typeof option === "string" ? option : option.label
}
filterOptions={(x) => {
return x;
}}
options={lstadresse}
isOptionEqualToValue={(option, value) =>
value.label === option.label
}
autoComplete
includeInputInList
filterSelectedOptions
value={adresse}
noOptionsText="Aucune adresse trouvée"
onChange={(event, newValue) => {
setLstAdresse(
newValue.name ? [newValue.name, ...lstadresse] : lstadresse
);
setAdresse(newValue.name);
if (newValue.name != "") {
setVille(newValue.city);
setCodePostal(newValue.postcode);
}
}}
onInputChange={(event, newInputValue) => {
setInputRue(newInputValue);
}}
renderInput={(params) => (
<div
ref={params.InputProps.ref}
className="login-block__input form_input_white"
>
<input
type="text"
name="adresse"
placeholder="Adresse"
{...params.inputProps}
/>
</div>
)}
/>
我们可以看到我已经集成了iSoptionequaltovalue参数而没有解决问题。在我的研究期间,其他人面临这个问题,并用我用Isoptionequaltovalue编写的内容解决了这一问题。如果有人有解决方案,我有兴趣。提前致谢。
When a value is entered in the input of the autocomplete component I get this warning that I can't remove...
This is what my input looks like
<Autocomplete
id="cboAdresse"
sx={{ width: 100 + "%", fontFamily: "Poppins Bold" }}
getOptionLabel={(option) =>
typeof option === "string" ? option : option.label
}
filterOptions={(x) => {
return x;
}}
options={lstadresse}
isOptionEqualToValue={(option, value) =>
value.label === option.label
}
autoComplete
includeInputInList
filterSelectedOptions
value={adresse}
noOptionsText="Aucune adresse trouvée"
onChange={(event, newValue) => {
setLstAdresse(
newValue.name ? [newValue.name, ...lstadresse] : lstadresse
);
setAdresse(newValue.name);
if (newValue.name != "") {
setVille(newValue.city);
setCodePostal(newValue.postcode);
}
}}
onInputChange={(event, newInputValue) => {
setInputRue(newInputValue);
}}
renderInput={(params) => (
<div
ref={params.InputProps.ref}
className="login-block__input form_input_white"
>
<input
type="text"
name="adresse"
placeholder="Adresse"
{...params.inputProps}
/>
</div>
)}
/>
We can see that I have integrated the IsOptionEqualToValue parameter without solving the problem. During my research other people have faced this problem and solved it with what I wrote with the IsOptionEqualToValue. If anyone has a solution I'm interested. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在MUI V5中使用此
in mui v5 use this
该解决方案是使用null代表自动完成组件的任何值。我在自动完成组件周围包装器中有以下代码。
由于使用NULL时会出现其他问题,因此需要清晰的Onblur。参见我的评论
The solution is to use null to represent no value for the Autocomplete component. I have the following code in my wrapper around the Autocomplete component.
The clear onBlur is needed because of other issues that pop up when using null. See my comment on their github for more details
我的解决方案是,假设输入:
警告出现:
没有警告,没有出现交战:
将状态绑定到自动填充以使其受到控制:
我的选择是:
底线:将null放入受控状态,为空,或者“无效” ,它将出现错误。
或者,自动完成作品的“ freesolo”属性,但它删除了下拉符号 /图标,因此并不理想。
my solution was, assuming CONTROLLED input:
WARNING appears:
NO WARNING, no warring appears:
Binding of state to the Autocomplete to make it controlled:
My options are:
Bottom line: put NULL into the controlled state, empty OR '' will NOT work, it will give error.
Alternatively 'freeSolo' property of AutoComplete WORKS, BUT it removes the DropDown symbol / icon, so not ideal.
使用
isoptionequaltovalue
属性如下Use the
isOptionEqualToValue
attribute like below我发现的唯一解决方案是仅在您的选项中添加一个空字符串。
The only solution I've found is to just add an empty string to your options.