I created a form and within I want 2 ways of submit :
- one by filling input field and press enter
- one by recording voice (I use the library react-speech-recognition)
Since I added the second way, the input field doesn't work. I can write something and press enter but it will necessarily call the function bind to the onClick of record-voice button, why ?
Here is the code of the main component
<form onSubmit={ handleSubmit } style={Style.myform}>
<Dictaphone values={values} write_speech={this.write_speech} perso={this.state.perso} question={this.state.question} />
<div className={Style.mydiv}>
<input className={Style.n_0} id="question" type="text" onChange={handleChange} value={values.question} disabled={isSubmitting} placeholder="Type here"/>
</div>
</form>
So here you can see the first method in the input and the second in the Dictaphone component, it calls the following function:
write_speech = (text, values) => {
console.log("write_speech");
console.log(values)
this.setState({question: document.getElementById("montexte").getAttribute("montexte")}, function () {
values['question'] = this.state.question
});
}
And the Dicatphone content :
return (
<div>
<button onClick={SpeechRecognition.startListening} type="button"> Start</button>
<button onClick={(transcript) => props.write_speech(transcript, props.values)}>Stop</button>
<button onClick={() => alert("toto")}>Reset</button>
<p id="montexte" type="text" className={Style.welcome_text} hidden={true} montexte={transcript} />
</div>
);
So I can click Start to record and Stop to call write_speech, but when I just use the main component and fill the input it necessarily call write_speech too. But I don't want that.
I made a simple test and curiously it doesn't call the 3rd button function () => alert("toto")
What I already tried: the 3 methods described in this post but the same problem persisted for me https://stackoverflow.com/a/34226188/10971146
Thanks for having read