更改事件从刺激JS未接收的Bootstrap-datepicker

发布于 2025-02-05 17:11:58 字数 1025 浏览 2 评论 0原文

是否有可能触发 signulus js js /uxsolutions/bootstrap-datepicker“ rel =“ nofollow noreferrer”> bootstrap-datepicker ? (我正在通过 bootstrap-datepicker-rails

$(document).on('changeDate', '#my_form .datepicker', function(e) {

更改事件也会在jQuery中触发(添加在这里a>?) 因此,更改更改为更改上面的更改工作相同。

但是更改事件没有在刺激中触发,例如我的datepicker文本字段:

data: { action: 'change->next-date#submit' }

不是在控制器中触发提交方法。 输入如果输入文本,将触发事件,但这不是datePicker触发的事件。 是否应该在此处更改事件对刺激不起作用?

Is it possible to trigger stimulus js from bootstrap-datepicker?
(I'm using it via bootstrap-datepicker-rails)

In my old jQuery code the changeDate event is triggered no problem:

$(document).on('changeDate', '#my_form .datepicker', function(e) {

The change event also gets triggered in jQuery (added here?)
So changing changeDate to change above works the same.

But the change event is not being triggered in Stimulus, EG on my datepicker text field:

data: { action: 'change->next-date#submit' }

isn't triggering the submit method in the controller. The input event will trigger if you enter text, but this is not the event triggered by the datepicker.
Should the change event not work here for Stimulus?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

メ斷腸人バ 2025-02-12 17:12:01

在刺激控制器的connect()方法中添加此方法来触发更改事件:

$(this.datepickerTarget).datepicker().on('changeDate', function(e) {
  const event = new Event('change')
  this.dispatchEvent(event)
})

这将数据action属性挂钩进入刺激方法:

          <%= text_field_tag :next_date, params[:next_date],
            data: { action: 'change->next-date#submit',
                    'next-date-target': 'datepicker'
            }
          %>

将钩子挂接到刺激方法中

Adding this in the stimulus controller's connect() method works to trigger the change event:

$(this.datepickerTarget).datepicker().on('changeDate', function(e) {
  const event = new Event('change')
  this.dispatchEvent(event)
})

This enables a data-action attribute hook into a stimulus method:

          <%= text_field_tag :next_date, params[:next_date],
            data: { action: 'change->next-date#submit',
                    'next-date-target': 'datepicker'
            }
          %>

to hook into a stimulus method

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文