I am using required attribute of html5 that make sure the field is not empty. I have a submit button and the validation is triggered after this button is pressed. I just want to keep this validation and not submit the form.
render() {
<form role="form">
<input type="number" value={this.state.value} required/>
<button type="submit" onClick={this.onFinish.bind(this)}>Submit</button>
</form>
}
onFinish(event) {
// event.target.checkValidity(); // something like this?
event.preventDefault();
}
When I use event.preventDefault() the form is not submitted but the validations are also not run. How can I do this? I do not want to write a custom validation for things like required, as they are already available and I want to use the existing one.