Javascript FlatPicker日历将不会保持打开状态

Javascript FlatPicker日历将不会保持打开状态,javascript,jquery,bootstrap-4,datepicker,flatpickr,Javascript,Jquery,Bootstrap 4,Datepicker,Flatpickr,我已经能够使用FlatPicker,通过一个输入字段进行精细初始化。我想在输入的一侧添加一个图标,用户可以单击该图标打开日历。我使用的是bootstrap,当涉及到输入组时,这可能会很有挑战性。我根本无法使[example][1]正常工作-当我使用{wrap:true}选项初始化时,使用该代码得到的只是一个没有显示任何日历图标的输入。如果有人有任何提示或一个完整的例子来说明如何让它工作,这将是理想的解决方案 由于我对文档中建议的方法没有把握,接下来我尝试通过使用jquery添加所需的元素来构建所

我已经能够使用FlatPicker,通过一个输入字段进行精细初始化。我想在输入的一侧添加一个图标,用户可以单击该图标打开日历。我使用的是bootstrap,当涉及到输入组时,这可能会很有挑战性。我根本无法使[example][1]正常工作-当我使用{wrap:true}选项初始化时,使用该代码得到的只是一个没有显示任何日历图标的输入。如果有人有任何提示或一个完整的例子来说明如何让它工作,这将是理想的解决方案

由于我对文档中建议的方法没有把握,接下来我尝试通过使用jquery添加所需的元素来构建所需的结构-我就快到了-我有一个图标可以打开输入字段旁边的日历,但日历会立即关闭-有时速度太快,看起来好像永远不会打开。这是我的密码:

HTML


js:将FlatPicker应用于页面上的每个日期字段

$.each($('.dateinput, .datetimeinput'), function () {
    if ($(this).hasClass("datetimepicker")) {
        if ($(this).hasClass("dateinput")) {
            picker_format = 'm/d/Y';
        }
        else {
            picker_format = 'm/d/Y, H:i';
        }
        var minDate = new Date().fp_incr(-parseInt($(this).attr("data-min-date")))
        var maxDate = new Date().fp_incr(parseInt($(this).attr("data-max-date")))
        $(this).wrap("<div class='flatpickr input-group'></div>");
        $('<a class="input-button" title="toggle" data-toggle><i class="fa fa-calendar"></i></a>').insertAfter(this);
        var calendar=$(this).flatpickr({
            allowInput: true,
            dateFormat: picker_format,
            minDate: minDate,
            maxDate: maxDate,
            //wrap: true,
        });
        $(this).next("a").click(function () {
            debugger;
            calendar.toggle();  //.open() does the same thing
        });
    }
});
$。每个($('.dateinput,.datetimeinput'),函数(){
if($(this).hasClass(“datetimepicker”)){
if($(this).hasClass(“dateinput”)){
选择器_格式='m/d/Y';
}
否则{
picker_格式='m/d/Y,H:i';
}
var minDate=new Date().fp_incr(-parseInt($(this).attr(“数据最小日期”))
var maxDate=new Date().fp_incr(parseInt($(this).attr(“数据最大日期”))
$(this.wrap(“”);
$('

$.each($('.dateinput, .datetimeinput'), function () {
    if ($(this).hasClass("datetimepicker")) {
        if ($(this).hasClass("dateinput")) {
            picker_format = 'm/d/Y';
        }
        else {
            picker_format = 'm/d/Y, H:i';
        }
        var minDate = new Date().fp_incr(-parseInt($(this).attr("data-min-date")))
        var maxDate = new Date().fp_incr(parseInt($(this).attr("data-max-date")))
        $(this).wrap("<div class='flatpickr input-group'></div>");
        $('<a class="input-button" title="toggle" data-toggle><i class="fa fa-calendar"></i></a>').insertAfter(this);
        var calendar=$(this).flatpickr({
            allowInput: true,
            dateFormat: picker_format,
            minDate: minDate,
            maxDate: maxDate,
            //wrap: true,
        });
        $(this).next("a").click(function () {
            debugger;
            calendar.toggle();  //.open() does the same thing
        });
    }
});