I want to submit a React form after clicking on the link.
To do this, I need to submit the form programmatically if the link is clicked.
My problem: the onSubmit handler does not start after the form is onSubmit .
Here is the code I made for this purpose:
var MyForm = React.createClass({ handleSubmit: function(e){ console.log('Form submited'); e.preventDefault(); }, submitForm : function(e){ this.refs.formToSubmit.submit(); }, render: function() { return ( <form ref="formToSubmit" onSubmit={this.handleSubmit}> <input name='myInput'/> <a onClick={this.submitForm}>Validate</a> </form>); } }); ReactDOM.render( <MyForm name="World" />, document.getElementById('container') );
handleSubmit not called and the default behavior is executed (the form is submitted). Is this a ReactJs bug or normal behavior? Is there a way to call the onSubmit handler?
reactjs forms onsubmit
Ahmed kooli
source share