Search code examples
javascripthtmlformsreactjs

Disable entire form elements with respect to a state. React


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>

Solution

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

    You should insert your a <fieldset disabled="disabled"> inside your form encapsulating the set of disabled fields.