如何使用Django和HTMX使用HTML日期类型

发布于 2025-01-22 15:19:17 字数 892 浏览 6 评论 0原文

我正在尝试从选择器获得日期,并在更改日期时触发HX-GET。下面的代码生成和文本输入字段,并弹出了datepicker。当我弹出datepicker并更改日期时,不会触发HX-GET。如果我单击文本输入区域,则使用选定的日期触发HX-GET。那么,当我从选择器中选择日期时,如何获得扳机激活呢?

我尝试了文本输入和dateInput小部件,但它们都以相同的方式行动。我玩过Django-bootstrap-datepicker-plus,但发现它与使用HTMX和脆皮形式的辅助助手布局的表格不佳。

谢谢

    datedue = forms.DateField(initial=timezone.now().date(),
                              label="On or before",
                              widget=forms.TextInput(attrs={'type': 'date',
                                    'hx-get': reverse_lazy('change-priority'),
                                    'hx-target': '#tasklist',
                                    'hx-include': '[name="priority"], [name="status"],[name="assigned"], [name="iscomplete"]',
                                    'hx-trigger': 'click change'
                                    })
                                )

I am trying to get date from a picker and trigger an hx-get when the date is changed. The code below produces and text input field with a datepicker pop up. When I pop up the datepicker and change the date, the hx-get is not triggered. If I then click in the text input area the hx-get is triggered with the picked date. So how do I get the trigger to activate when I select the date from the picker?

I tried both the TextInput and DAteInput widgets but they both act the same way. I played a bit with django-bootstrap-datepicker-plus but found it did not work well with my forms which use both HTMX and Crispy forms helper layouts.

Thanks

    datedue = forms.DateField(initial=timezone.now().date(),
                              label="On or before",
                              widget=forms.TextInput(attrs={'type': 'date',
                                    'hx-get': reverse_lazy('change-priority'),
                                    'hx-target': '#tasklist',
                                    'hx-include': '[name="priority"], [name="status"],[name="assigned"], [name="iscomplete"]',
                                    'hx-trigger': 'click change'
                                    })
                                )

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

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

发布评论

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

评论(1

往昔成烟 2025-01-29 15:19:17

您需要将事件与a comma

datedue = forms.DateField(initial=timezone.now().date(),
                          label="On or before",
                          widget=forms.TextInput(attrs={'type': 'date',
                                'hx-get': reverse_lazy('change-priority'),
                                'hx-target': '#tasklist',
                                'hx-include': '[name="priority"], [name="status"],[name="assigned"], [name="iscomplete"]',
                                'hx-trigger': 'click, change'
                                })
                            )

空间分离器用于事件修饰符,例如更改延迟:1s

You need to separate the events with a comma.

datedue = forms.DateField(initial=timezone.now().date(),
                          label="On or before",
                          widget=forms.TextInput(attrs={'type': 'date',
                                'hx-get': reverse_lazy('change-priority'),
                                'hx-target': '#tasklist',
                                'hx-include': '[name="priority"], [name="status"],[name="assigned"], [name="iscomplete"]',
                                'hx-trigger': 'click, change'
                                })
                            )

The space separator is used for event modifiers, e.g. change delay:1s.

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