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

Pressing enter on DayPickerInput inside a form causes submit #856

Closed
grayChilli opened this issue Jan 22, 2019 · 4 comments
Closed

Pressing enter on DayPickerInput inside a form causes submit #856

grayChilli opened this issue Jan 22, 2019 · 4 comments

Comments

@grayChilli
Copy link

grayChilli commented Jan 22, 2019

Similar as minor bug #443.
It's about day picker input with dropdown calendar.
Even when read-only, read-only input field could receive focus. If you press enter the form will be submited.

<DayPickerInput
  placeholder="DD/MM/YYYY"
  onKeyPress={e => {
    e.target.keyCode === 13 && e.preventDefault();
  }}
  inputProps={{
    disabled: this.state.locked,
    readOnly: true,
    name: "datepick",
    type: "text"
  }}
  dayPickerProps={{ localeUtils: MomentLocaleUtils, locale: "de" }}
  value={this.state.mydate}
  formatDate={formatDate}
  onDayChange={this.handleDate}
/>;
@gpbl
Copy link
Owner

gpbl commented Feb 21, 2019

This is the desired behavior. What do you expect to happen instead?

@grayChilli
Copy link
Author

There is a form with a more than 10 fields. I would like to prevent users from accidentally submitting a form by hitting Enter on any field including dayPickerInput. preventDefault does not work with dayPickerInput.

@gpbl
Copy link
Owner

gpbl commented Feb 25, 2019

If you want to prevent a submit you should prevent the submit default event, like:

<form onSubmit={e=>e.preventDefault()} />

@frrodriguez
Copy link

Hi, i have the same issue, with another buttons.

The UI buttons to swipe between months '<>' also triggers sumbit on uppers form.

If i just inspect these buttons and adds type="button" to them, works correctly.

All buttons in html are type="submit" if omits, then i think these buttons must be type "button".

Do not force us to use e.preventDefault() on forms, casue we can need in other situations.

Thx

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