简体   繁体   English

bootstrap-datetimepicker enabledDates 未按预期工作

[英]bootstrap-datetimepicker enabledDates not working as expected

bootstrap-datetimepicker引导日期时间选择器

I am using this plugin and having issues in enabling certain dates.我正在使用这个插件并且在启用某些日期时遇到问题。

This snippet correctly enables dates during initialization.此代码段在初始化期间正确启用日期。

$("#example-datepicker").datetimepicker({
    locale: "en",
    format: 'M.D.YYYY',
    useCurrent: true,
    enabledDates: ['2020-07-24', '2020-08-25']
});

But after initialization, when I wanna update enabled dates, it doesn't work.但是初始化后,当我想更新启用日期时,它不起作用。

$("#example-datepicker").data("DateTimePicker").enabledDates(['2020-02-24', '2020-05-25']);

Any help is much appreciated!任何帮助深表感谢!

PS: Are there any other plugins that can control what dates to enable? PS:还有其他插件可以控制启用哪些日期吗?

Add extraFormats in initialization.在初始化中添加extraFormats

$("#example-datepicker").datetimepicker({
    locale: "en",
    format: 'M.D.YYYY',
    extraFormats: ['YYYY-MM-DD'],
    useCurrent: true,
    enabledDates: ['2020-07-24', '2020-08-25']
});

By adding that, the plugin can understand dates provided in enabledDates .通过添加,插件可以理解enabledDates中提供的日期。
The reason it was rendered correctly at initialization is that since YYYY-MM-DD is a standard Date format, it is recognized.它在初始化时正确呈现的原因是由于YYYY-MM-DD是标准日期格式,因此可以识别。
But after initialization ( format has been specified), it can no longer recognize the standard format.但是初始化后( format已经指定),就不能再识别标准格式了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM