0
I am developing a project, and when typing a value in a field I need the other field to be changed based on the values I set in a function, here is the code:
constructor(props) {
super(props);
this.state = {
rendimentoMes: '',
risco: '',
}
}
changeRendimentoMesHandler= (event) => {
this.setState({rendimentoMes: event.target.value});
}
changeRiscoHandler= (event) => {
this.setState({risco: event.target.value});
}
In the function below I check the value that will be inserted in field Monthly income, which should have an impact on the risk field:
defineRisco(){
if (this.state.rendimentoMes != null){
if (this.state.rendimentoMes > 6000){
this.state.risco = "A";
} else if (this.state.rendimentoMes > 1000 && this.state.rendimentoMes <= 8000){
this.state.risco = "B";
} else {
this.state.risco = "C";
}
}
}
And here’s my yield, where it should be dynamically upgraded according to field value Monthly income. I’m trying to accomplish this way, someone helps me know where I’m going wrong?
render() {
return (
<div>
<div className="form-group">
<label> Rendimento Mensal: </label>
<input type ="Number" placeholder="Rendimento Mensal:" name="rendimentoMes" className="form-control"
value={this.state.rendimentoMes} onChange={this.changeRendimentoMesHandler} blur={this.defineRisco} />
</div>
<div className="form-group">
<label> Risco: </label>
<input disabled type ="Number" placeholder="" name="risco" className="form-control"
value={this.state.risco} onChange={this.defineRisco()} />
</div>
</form>
</div>
</div>
</div>
</div>
)
}
saw the answers?
– novic