I would like to stop the validation event to be called when I press the enter key in the form. Indeed I have a custom autocomplete widget and a lot of people press enter key to validate it. But it calls validation and it's very disturbing but I don't find a solution to stop it.
I would like to do somthing like this :
submitAction(event) {
if (event.which === 13 /* Enter */) {
event.preventDefault();
}
}
But the function I call in onSubmit is not called after an enter key press.
Validation is not triggered when I press the enter key
Pressing enter key call validation form.
If you have any ideas please help me :)
Thank you !
Ok I don't know if it's a good or bad practise but I had
componentWillMount() {
document.addEventListener("keydown", this._handleKeyDown.bind(this));
}
_handleKeyDown(event) {
//enter key code is 13
if (event.keyCode === 13) {
event.preventDefault();
}
}
And now it works well and stop event.
Can you please provide an example code of the autocomplete widget.
Thank you.
@marinav great you solved your problem, closing this.
@utajum , autocomplete is an attribute (https://github.com/mozilla-services/react-jsonschema-form#form-attributes). Feel free to open another issue if you have a specific question about it.
Most helpful comment
Ok I don't know if it's a good or bad practise but I had
And now it works well and stop event.