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

Exception when input is not a valid date #1182

Closed
Phyks opened this issue Jan 3, 2018 · 5 comments
Closed

Exception when input is not a valid date #1182

Phyks opened this issue Jan 3, 2018 · 5 comments

Comments

@Phyks
Copy link

Phyks commented Jan 3, 2018

Reproduction Link

https://jsfiddle.net/tj2Lo4z7/

Your Environment

  • flatpickr version used: 4.1.4

Hi,

When putting anything (but not a valid date) in the input field (with allowInput: true) and pressing "Enter", an exception is thrown in the dev console:

Error: Invalid date provided: toto
Stack trace:
parseDate@http://localhost:9876/main.js:80266:38
setSelectedDate@http://localhost:9876/main.js:80106:30
setDate@http://localhost:9876/main.js:80131:9
onKeyDown@http://localhost:9876/main.js:79661:17
EventListener.handleEvent*bind@http://localhost:9876/main.js:78942:9
bindEvents@http://localhost:9876/main.js:78975:13
init@http://localhost:9876/main.js:78824:9
FlatpickrInstance@http://localhost:9876/main.js:80478:5
…

I guess there should be a check that the value is a correct date.

Thanks!

@chmln
Copy link
Member

chmln commented Jan 3, 2018

Hello,

flatpickr does check whether the input is a valid date.
Its not an exception, but a console warning.
You can handle errors yourself if you dont want them in the console.

Use the errorHandler option.

{
  errorHandler: (error) => { 
    // do something
  }

@chmln chmln closed this as completed Jan 3, 2018
@Phyks
Copy link
Author

Phyks commented Jan 3, 2018

Oh, ok, I missed the errorHandler setting. Thanks! (sorry for the noise :/)

@chmln
Copy link
Member

chmln commented Jan 3, 2018

No problem 👍. It should really be documented better

@bnjbvr
Copy link

bnjbvr commented Jan 15, 2018

Sorry, I think this issue isn't quite done yet: if you create a Flatpickr instance and pass it an errorHandler function, then the following happens:

This means that even if we pass options, if the parser created with createDateParser survives, then the error handler will be plainly ignored, since it's going to use the default one.

Can you reopen the issue, please?

@chmln
Copy link
Member

chmln commented Jan 18, 2018

@bnjbvr fixed in #1196

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