I am trying to disable a submit button on some condition but it doesn't work. When I inspect the element in the browser, this is what is rendered regardless of whether the condition returns true or false.
Element as rendered in browser
<button type="submit" disabled="" class="bg-yellow-500 text-white mt-4 disabled:bg-yellow-300 px-3 py-2 rounded-md">Submit</button>
Code
state = {
formIsVaild: false
}
render() {
<button type="submit" disabled={!this.state.formIsVaild} className="bg-yellow-500 text-white mt-4 disabled:bg-yellow-300 px-3 py-2 rounded-md">Open Discussion</button>
}
I even removed the condition and tried this...
state = {
formIsVaild: false
}
render() {
<button type="submit" disabled className="bg-yellow-500 text-white mt-4 disabled:bg-yellow-300 px-3 py-2 rounded-md">Open Discussion</button>
}
No matter what value I pass to the disable attribute, disabled="" get's rendered in the HTML. I even tried to use an input with type submit instead of a button and I'm getting the same result. I am not sure what is going on here... any help?
Minimal example
import React, { Component } from 'react';
class FormData extends Component {
state = {
formIsVaild: false
}
render() {
return (
<div className="grid grid-cols-3 gap-4">
<div className="col-span-2">
<form>
<button type="submit" disabled={!this.state.formIsVaild} className="bg-yellow-500 text-white mt-4 disabled:bg-yellow-300 px-3 py-2 rounded-md">Submit</button>
</form>
</div>
</div>
)
}
}
export default FormData