bootstrap-datepicker.js使用今天清除日期的日期 [英] bootstrap-datepicker.js using today's date when date cleared

查看:120
本文介绍了bootstrap-datepicker.js使用今天清除日期的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用bootstrap-datepicker.js,非常好的插件。一切都按预期工作,减去这一个案例,这可能是我在文档中遗漏了一些东西。每当用户输入日期并且文本框失去焦点(用户继续完成表单的其余部分)时,如果用户返回文本框并尝试删除日期,则会自动填充今天的日期。如果您删除今天的日期,它会重复自动填充...有没有我错过的选项会纠正这种情况?如果该字段是必需的,那么这不是什么大问题,但是用户可以选择在没有日期的情况下提交表单。代码如下:

Using bootstrap-datepicker.js, very nice plugin. Everything works as expected, minus this one case, which could be me missing something within the documentation. Whenever a user enters a date and the textbox looses focus (user goes on to complete the rest of the form), if the user goes back to the textbox and attempts to remove the date, today's date is automatically populated. If you remove today's date, it automatically populates again...repeatedly. Is there an option I have missed that would rectify this situation? If the field was required, it wouldn't be a big deal, however the user has the option of submitting the form without a date. Code below:

       $('#start_date').datepicker({
            orientation: "bottom auto",
            autoclose: true,
            todayHighlight: true,
            useCurrent: false
        }).mask("99/99/9999");

        $('#end_date').datepicker({
            orientation: "bottom auto",
            autoclose: true,
            todayHighlight: true,
            useCurrent: false
        }).mask("99/99/9999");

这是一个证明问题的工作小提琴: https://jsfiddle.net/f8v5vLmt/3/

This is a working fiddle demonstrating the issue: https://jsfiddle.net/f8v5vLmt/3/

推荐答案

您使用的掩码插件一定存在问题。它在 datetime picker 正在尝试解析的字段中设置一个值,它显然不是日期,所以它必须默认为当前日期。

There must be a problem with the mask plugin you are using. It is setting a value in the field that datetime picker is trying to parse, and it is obviously not a date, so it must be defaulting to current date.

尝试将 forceParse:false 添加到选项中。

你可以在这里的第一个字段中检查行为是否是你想要的:

You can check the behaviour is whatyou want in the first field here:

https://jsfiddle.net/f8v5vLmt/5/

参考: https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#forceparse

这篇关于bootstrap-datepicker.js使用今天清除日期的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆