Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to disable the validation call triggered by pressing the enter key #839

Closed
2 tasks done
marinav opened this issue Feb 12, 2018 · 3 comments
Closed
2 tasks done

Comments

@marinav
Copy link
Collaborator

marinav commented Feb 12, 2018

Prerequisites

  • I have read the documentation;
  • 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 !

@marinav
Copy link
Collaborator Author

marinav commented Feb 13, 2018

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.

@utajum
Copy link

utajum commented Feb 20, 2018

Can you please provide an example code of the autocomplete widget.

Thank you.

@epicfaace
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants