React-jsonschema-form: Way to disable the validation call triggered by pressing the enter key

Created on 12 Feb 2018  路  3Comments  路  Source: rjsf-team/react-jsonschema-form

Prerequisites

  • [x] I have read the documentation;
  • [x] In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

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.

Expected behavior

Validation is not triggered when I press the enter key

Actual behavior

Pressing enter key call validation form.

If you have any ideas please help me :)

Thank you !

Most helpful comment

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ebower12 picture ebower12  路  3Comments

n1k0 picture n1k0  路  3Comments

mfulton26 picture mfulton26  路  3Comments

sstarrAtmeta picture sstarrAtmeta  路  3Comments

MedinaGitHub picture MedinaGitHub  路  3Comments