admin管理员组文章数量:1279049
I had a condition if the two textfield are the same it will proceed, if not then the button is disabled. I know I'm doing this wrong.
onSubmit() {
debugger
if (this.state.password == this.state.password2)
alert('same');
else
alert('error');
this.disable;
}
I had a condition if the two textfield are the same it will proceed, if not then the button is disabled. I know I'm doing this wrong.
onSubmit() {
debugger
if (this.state.password == this.state.password2)
alert('same');
else
alert('error');
this.disable;
}
Share
Improve this question
edited Dec 20, 2019 at 17:38
Dharman♦
33.4k27 gold badges101 silver badges147 bronze badges
asked Jun 5, 2017 at 9:10
P.MacsP.Macs
771 gold badge3 silver badges16 bronze badges
1
- Pro tips for posting: (1) please do not offer voting advice. If people wish to vote on your posts, they will, and asking for people not to downvote will probably have the opposite effect; (2) try to refrain from "please help me" and other forms of begging and pleading - it's another good way to get downvotes. Experienced users find it annoying, since hundreds of people beg every single day. (3) When referring to yourself, please use a capital letter "I" - all-lower-case posting might be OK on Facebook, but readability is important here. Thanks! – halfer Commented Aug 21, 2017 at 17:52
3 Answers
Reset to default 4First, dont check onSubmit but on change (you dont want to disable it AFTER it was submitted) for both your input. Add a state value for your disabledButton, and set it to false only if both input are the same (in the onChange event).
You can set disabled button inside your JSX like this
<button disabled={this.state.disabledButton} />
You can do that in your render
function:
render() {
const submitDisabled = this.state.password !== this.state.password2
return (
// ...
<button disabled={submitDisabled}>Submit</button>
// ...
)
}
This will work Perfect. Try this
render() {
const submitDisabled = password.length > 0
return (
// ...
<button disabled={submitDisabled}>Submit</button>
// ...
)
}
本文标签: javascriptHow to disable button onclick in ReactjsStack Overflow
版权声明:本文标题:javascript - How to disable button onclick in Reactjs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741302413a2371166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论