Disable entire form elements with respect to a state. React

社会主义新天地 提交于 2021-01-20 17:46:07

问题


I am disabling the inputs using the isFetching prop, but this is getting reduntant as I have to keep this in every input field. Is there a way to disable the entire form? Like a disable property in <form> tag or something?

<form>
  <input type="text" disabled={this.props.isFetching} />
  <input type="text" disabled={this.props.isFetching} />
</form>

回答1:


I think this should solve your problem https://stackoverflow.com/a/17186342/3298693.

You should insert your form inside an element <fieldset disabled="disabled">. This will make the whole form disabled.




回答2:


I had the same issue and this worked for me:

 <fieldset disabled={true}>

Where true would be some "prop.setting"...




回答3:


Just use <input type="text" disabled> wherever you want the input text to be disabled. It hardly takes some time.



来源:https://stackoverflow.com/questions/36215244/disable-entire-form-elements-with-respect-to-a-state-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!