Answer the question
In order to leave comments, you need to log in
How to change disabled element in react.js?
At the time of receiving the data, I want to deactivate the "send" button, through the attribute of the disabled tag.
I do it like this:
var LogIn = React.createClass({
getInitialState: function(){
return {
disabled: "enable";
};
},
submitLogin: function() {
....
$.ajax({
....
beforeSend: function() {
this.setState({
disabled: "disabled"
});
},
....
complete: function (){
this.setState({
disabled: "enable"
});
},
....
})
....
},
render: function(){
return(
<form method="post" id="registration" className="message">
..........
<p><input type="submit" value="Отправить" onClick={this.submitLogin} disabled={this.state.disabled} /></p>
</form>
);
}
})
Answer the question
In order to leave comments, you need to log in
In React, the disabled attribute accepts a bool, meaning disabled={false} will make the element active
Well, in fact, you are doing everything fine, here is a poor working example:
HTML:
<div class="container">
</div>
var Test = React.createClass({
getInitialState: function() {
return {disabled: true};
},
clickHandlers: function() {
this.setState({disabled: false});
},
render: function() {
return (
<div>
<button disabled={this.state.disabled}>Тест</button>
<button onClick={this.clickHandlers}>Сменить</button>
</div>
);
}
});
React.renderComponent(Test({}), document.querySelector(".container"));
beforeSend: function() {
this.setState({
disabled: "disabled"
});
},
....
complete: function (){
this.setState({
disabled: "enable"
});
}
submitLogin: function() {
var that = this;
....
$.ajax({
....
beforeSend: function() {
that.setState({
disabled: "disabled"
});
},
....
complete: function (){
that.setState({
disabled: "enable"
});
},
....
})
....
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question