如何清除MUI自动完成至初始状态
我想重置/清除我的MUI自动完成组件。 我有两个带有{label:string,value:string}
的模型的模型,如果第一个更改其值,那么我想清除第二个一。
此外 - 我正在使用用
setValue
进行react-hook-form
。我在此方法中用作值{label:'',value:''}
,但会导致警告说,在我的新选项中,没有这样的选择(我认为这是次要的问题),但它不会重置第二个自动完成输入,而是部分重置。我仍然看到x
清除值。我在null
中使用了setValue
中的值,但也没有防滑输入。
我要实现的是 - 在第一个输入上选择一些选项,我想重置第二个输入,例如单击x
做。是否可以 ?
干杯!
I would like to reset/clear my MUI Autocomplete component.
I have two of them with model like { label: string, value: string }
and if first will change its value then I would like to clear the second one since second will get options by selected value in first one.
Moreover - I am using react-hook-form
with setValue
. I use as value in this method { label: '', value: '' }
but it causes warning that in my new sort of options there is no such option to select (this is minor issue I think) but it does not reset second Autocomplete input but partially. I still see X
to clear value. I used null
as value in setValue
but it does not cleat input as well.
What I want to achieve is - selecting some option on first input I would like to reset second input like clicking on X
does. Is it possible ?
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现是什么原因引起了我上面描述的问题。这是因为用
clearonblur = {false}
props声明了我的代码库中的自动完成。当我执行setValue(autoCompleteFieldName,null,null)
通过react> react-hook-form
时,它阻止了我的自动完成的价值。我希望它能对一个奇怪的问题有帮助,因为我根本没有与输入进行互动以调用onblur
事件。干杯!I found what caused the issue I describe above. It was because Autocomplete in my codebase was declared with
clearOnBlur={false}
props. It prevented to clear value of my Autocomplete when I was doingsetValue(autocompleteFieldName, null)
viareact-hook-form
. I hope it helps someone with the same strange issue since I was not interacting with input at all to invokeonBlur
event. Cheers!