【问题标题】:How to implement bootstrap datepicker with text_field? [closed]如何使用 text_field 实现引导日期选择器? [关闭]
【发布时间】:2023-03-10 08:50:01
【问题描述】:

我想在 form_for 中使用带有我的 text_field 的引导日期选择器。 我应该如何重写

 <%= f.text_field :some_date %>

在 some_date 字段中存储所选日期的行?

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap datepicker


    【解决方案1】:

    日期时间选择器仅支持input 类型以进行直接集成。但是轨道text_field 创建text area。所以你不能直接这样做。

    您可以集成 datetimepicker onclick 或 mousedown 事件。就像我们可以为 div/span 做的一样。

    如果你想这样做,你需要覆盖检查支持的 html 元素的 datetimepicker 代码。

    下面的代码应该改变:link here

    attachDatePickerElementEvents = function () {
        input.on({
            'change': change,
            'blur': options.debug ? '' : hide,
            'keydown': keydown,
            'keyup': keyup,
            'focus': options.allowInputToggle ? show : ''
        });
    
        if (element.is('input')) {
            input.on({
                'focus': show
            });
        } else if (component) {
            component.on('click', toggle);
            component.on('mousedown', false);
        }
    },
    

    【讨论】:

      【解决方案2】:

      看到这个Demo & codeAPI

      $('字段选择器').datepicker({ });

      【讨论】:

      • 谢谢。我会尝试回答
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 2020-03-07
      • 2012-10-10
      相关资源
      最近更新 更多