Use idiomorph and a delay in the booking form

This is specially for the departure date: Firefox triggers a change each
time the user writes something, but since the date may be outside the
allowed range while the user is typing, the form replaces the input with
the “corrected” one.  The idiomorph thing is to keep the focus in the
“same” field, from the point of view of the user.

It still happens if one is slow enough, but i guess people that want to
write instead of picking the date are usually fast typist. Let’s hope.
This commit is contained in:
jordi fita mas 2024-02-27 20:04:04 +01:00
parent 97831668e5
commit 80835256cc
3 changed files with 9 additions and 1 deletions

1
web/static/idiomorph-ext@0.3.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -21,7 +21,8 @@
</fieldset> </fieldset>
{{ with .Dates -}} {{ with .Dates -}}
<fieldset class="booking-period" <fieldset class="booking-period"
data-hx-get="/{{ currentLocale }}/booking" data-hx-trigger="change" data-hx-get="/{{ currentLocale }}/booking"
data-hx-trigger="change delay:1000ms"
> >
<legend>{{( pgettext "Booking Period" "title" )}}</legend> <legend>{{( pgettext "Booking Period" "title" )}}</legend>
{{ with .ArrivalDate -}} {{ with .ArrivalDate -}}

View File

@ -7,6 +7,10 @@
{{( pgettext "Booking" "title" )}} {{( pgettext "Booking" "title" )}}
{{- end }} {{- end }}
{{ define "head" -}}
<script src="/static/idiomorph-ext@0.3.0.min.js"></script>
{{- end }}
{{ define "content" -}} {{ define "content" -}}
{{- /*gotype: dev.tandem.ws/tandem/camper/pkg/booking.publicPage*/ -}} {{- /*gotype: dev.tandem.ws/tandem/camper/pkg/booking.publicPage*/ -}}
<h2>{{ template "title" . }}</h2> <h2>{{ template "title" . }}</h2>
@ -21,6 +25,8 @@
</div> </div>
{{- end }} {{- end }}
<form id="booking" action="/{{ currentLocale }}/booking" method="post" <form id="booking" action="/{{ currentLocale }}/booking" method="post"
data-hx-ext="morph"
data-hx-swap="morph:innerHTML"
data-hx-include="this" data-hx-include="this"
data-hx-target="this" data-hx-target="this"
data-hx-replace-url="true" data-hx-replace-url="true"