Reputation: 1760
I wanna that into an OnChange, this event calls to 2 different functions with ReactJS. I have tried several forms but I have not success. I have tried:
/*This is my text area, into ONCHANGE I put options shown below*/
<textarea name="NAME" id="ID" ONCHANGE placeholder="PLACEHOLDER" maxLength="4000" rows="7" class="form-control" required></textarea>
/*This way give me error*/
onChange={this.activarBotonEnviar this.contadorDeCaracteres}
/*This way give me error*/
onChange={this.activarBotonEnviar; this.contadorDeCaracteres}
/*This way only execute last function*/
onChange={this.activarBotonEnviar, this.contadorDeCaracteres}
/*This way only execute last function*/
onChange={this.activarBotonEnviar} onChange={this.contadorDeCaracteres}
I am working with ReactJS. I hope you could help me. Thank you all.
Upvotes: 2
Views: 7507
Reputation: 104539
How it is possible for a variable/property to hold two values at the same time?
We can assign a single function to Onchange event, so what you can do is either create a new function and call these two function from that or call one from another.
Creating new Function:
onChange = { (e) => { this.activarBotonEnviar(e); this.contadorDeCaracteres(e) } }
Calling one function from another:
onChange = { this.activarBotonEnviar }
and call contadorDeCaracteres
from activarBotonEnviar
function:
activarBotonEnviar(e){
...
this.activarBotonEnviar();
}
Upvotes: 3
Reputation: 7774
onChange={this.myFunc}
myFunc(){
this.activarBotonEnviar();
this.contadorDeCaracteres();
}
Upvotes: 3