flatpickr js 不断将日期恢复到 2022 年 1 月 1 日
我使用 flatpickr 作为 html/js 中的日期选择器。我使用 jsdelivr 拉取该模块:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
多年来它一直表现正常,但昨天它开始表现奇怪。这是我的 javascript,我没有更改:
$("input[type='datetime'], input[type='datetime-local']").flatpickr({
enableTime: true,
altInput: true,
altFormat: "F j, Y at h:i K",
dateFormat: "Y-m-d H:i",
time_24hr: false
});
当我选择日期时,datepicker flatpickr-input
类的值更改为所选的日期时间,并且 datepicker form-control input
类更改其值命名为日期选择器表单控件输入处于活动状态
。我认为这都是预料之中的。
问题是,当我第二次单击(在另一个日期或在日历 div 之外)时,日期时间会删除我的选择并将其替换为 2022-01-01 00:00
。
为什么要这样做而不是保留我选择的值?
I'm using flatpickr as a datepicker in html/js. I pull the module in using jsdelivr:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
It's been behaving normally for years, but yesterday it started behaving oddly. Here is my javascript, which I have not changed:
$("input[type='datetime'], input[type='datetime-local']").flatpickr({
enableTime: true,
altInput: true,
altFormat: "F j, Y at h:i K",
dateFormat: "Y-m-d H:i",
time_24hr: false
});
And that displays a datepicker like so:
When I select a date, the value of the datepicker flatpickr-input
class changes to the datetime chosen and the datepicker form-control input
class changes its name to datepicker form-control input active
. I think that's all expected.
The problem is that when I click a second time (either on another date or outside of the calendar div), the datetime removes my selection and replaces it with 2022-01-01 00:00
.
Why is it doing that rather than keeping the value I select?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有类似的问题,看起来是最新版本的 4.6.10。恢复到 4.6.9 似乎可以解决该问题。
更多信息请参见:
https://github.com/flatpickr/flatpickr/issues/2655
Having a similar issue, looks like it's with the latest version of 4.6.10. Reverting to 4.6.9 seems to fix the issue.
More here:
https://github.com/flatpickr/flatpickr/issues/2655