Let's say I have this HTML:
<div id="container"></div>
<p>Output: <span id="output"></span></p>
and this JS:
function otherAction(e) {
document.getElementById('output').innerHTML = 'otherAction';
e.preventDefault();
}
function submit(e) {
document.getElementById('output').innerHTML = 'submit';
e.preventDefault();
}
ReactDOM.render(
<form onSubmit={submit}>
<input type="text" defaultValue="foo" />
<button onClick={otherAction}>Other Action</button>
<button type="submit">Submit</button>
</form>,
document.getElementById('container')
);
Actually, let's not just say it, let's put it in a JSFiddle example. What I want to happen is that:
Clicking the "Other Action" button triggers the otherAction
function (it does!)
Clicking the "Submit" button triggers the submit
function (it does!)
Putting your cursor in the text box and pressing enter triggers the submit
function (this does not work currently!)
In #3, what happens instead is that otherAction
gets triggered. How can I change that?
Multiple selection ButtonGroup supports checkbox type selection in which multiple button can be selected. This can be achieved by adding input element along with id attribute with its corresponding label along with htmlFor attribute inside the target element.
React JS, two submit buttons in one form - Stack Overflow // You need to add a onSubmit event to the form. This will trigger when you submit the for as you do any other html form (including pressing the submit button) <form onSubmit={this.
If you set the first button to type="button" it should work.
<button type="button" onClick={otherAction}>Other Action</button>
https://jsfiddle.net/L0urqamz/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With