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
Input value not updated when manually changed and allowInput: true, altInput: true #639
Comments
Based on your comment here, I tried adding a parseDate: function(dateString) { ... } I couldn't tell from the docs whether my Given that I only need to support two parseDate: function(dateString) {
var match;
// dateFormat
match = dateString.match(/(\d{4})-(\d{2})-(\d{2})/);
if (match != null) {
return new Date(match[1], match[2] - 1, match[3]);
}
// altFormat 1
match = dateString.match(/(\d{2})\.(\d{2})\.(\d{4})/);
if (match != null) {
return new Date(match[3], match[2] - 1, match[1]);
}
// altFormat 2
match = dateString.match(/(\d{1,2}) (\w{3}) (\d{4})/);
if (match != null) {
return new Date(dateString);
}
// unparseable
return new Date();
} Without my Anyway, is this the correct way to go? |
@airblade Yes that's the way to go for now. I've been seriously considering integrating a date parser, however. |
OK, thanks for the confirmation. I think the docs explain the difference between Regarding a date parser: I'd be happy with a very simple, no-surprises one built in; and the capability to replace it with something else, if I needed something more sophisticated. In other words, don't clog up Flatpickr with a complicated date parser because Flatpickr's value is as a lightweight datetime picker, not a parser. Let a dedicated external parser handle the parsing and all the weird edge cases. For example rome leans on moment.js. Anyway, thanks for a great plugin! |
*dig You could also emit an enter press after blur occurs:
|
@Comp0ser As mentioned in issue #1551 (comment) this can be done simply in the config object. |
I needed something similar - came across numerous suggestions online (but none seemed to work) found 2 pull requests claiming to fix this issue (over a year old, frustrating!) So using this as a base, this is what i came up with that seems to work on flatpickr v4.6.13
|
Expected Behavior
I am trying to produce a text input field which the user can edit manually, and which displays the date in the UI in one format while always storing the date value in another format. Here's my code:
HTML:
JS:
The calendar picker itself works perfectly: the input field displays the date in its
altFormat
(e.g.23 Feb 2017
) and it is submitted to the server in thedateFormat
(e.g.2017-02-23
), as expected.I would expect to be able to type (directly into the input) a date in the same format as the displayed date.
Current Behavior
When I type directly into the input, the date I typed is not submitted when the form is submitted. Instead the original value is submitted.
Possible Solution
I'm new to this codebase, but it looks like
altInput: true
leads flatpickr to hide the original input and create a new one showing the date in itsaltFormat
. I would guess that direct, non-calendar-picker changes to the visible input field are somehow not being passed on properly to the hidden input field.UPDATE: after reading #578, I wonder whether this is due to parsing. I would expect to be able to directly type a date in the same format as the displayed date, i.e.
altFormat
. Maybe, though, it only works if I type a date in the underlying format, i.e.dateFormat
. I tried it, and it works (if and only if) I also press<enter>
straight afterwards. But that is impossible for the user to figure out; if we're displaying dates inaltFormat
, we should accept manually typed dates inaltFormat
.Your Environment
The text was updated successfully, but these errors were encountered: