如何使用Django和HTMX使用HTML日期类型
我正在尝试从选择器获得日期,并在更改日期时触发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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将事件与a comma 。
空间分离器用于事件修饰符,例如
更改延迟:1s
。You need to separate the events with a comma.
The space separator is used for event modifiers, e.g.
change delay:1s
.