From 440e1cfb719f233bd44a0a1d3983b4342273be32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sat, 30 Sep 2023 12:40:02 +0200 Subject: [PATCH] Focus important fields on forms --- CHANGELOG.md | 1 + games/forms.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af6907e..947f6b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Add copy button on Add session page to copy times between fields * Use the same form when editing a session as when adding a session * Add a hacky way not to reload a page when starting or ending a session (https://git.kucharczyk.xyz/lukas/timetracker/issues/52) +* Focus important fields on forms ## 1.0.3 / 2023-02-20 17:16+01:00 diff --git a/games/forms.py b/games/forms.py index 9a01bd1..e83606a 100644 --- a/games/forms.py +++ b/games/forms.py @@ -6,6 +6,8 @@ custom_date_widget = forms.DateInput(attrs={"type": "date"}) custom_datetime_widget = forms.DateTimeInput( attrs={"type": "datetime-local"}, format="%Y-%m-%d %H:%M" ) +autofocus_select_widget = forms.Select(attrs={"autofocus": "autofocus"}) +autofocus_input_widget = forms.TextInput(attrs={"autofocus": "autofocus"}) class SessionForm(forms.ModelForm): @@ -13,7 +15,8 @@ class SessionForm(forms.ModelForm): # queryset=Purchase.objects.filter(date_refunded=None).order_by("edition__name") # ) purchase = forms.ModelChoiceField( - queryset=Purchase.objects.order_by("edition__name") + queryset=Purchase.objects.order_by("edition__name"), + widget=autofocus_select_widget, ) class Meta: @@ -38,7 +41,9 @@ class EditionChoiceField(forms.ModelChoiceField): class PurchaseForm(forms.ModelForm): - edition = EditionChoiceField(queryset=Edition.objects.order_by("name")) + edition = EditionChoiceField( + queryset=Edition.objects.order_by("name"), widget=autofocus_select_widget + ) platform = forms.ModelChoiceField(queryset=Platform.objects.order_by("name")) class Meta: @@ -59,7 +64,9 @@ class PurchaseForm(forms.ModelForm): class EditionForm(forms.ModelForm): - game = forms.ModelChoiceField(queryset=Game.objects.order_by("name")) + game = forms.ModelChoiceField( + queryset=Game.objects.order_by("name"), widget=autofocus_select_widget + ) platform = forms.ModelChoiceField(queryset=Platform.objects.order_by("name")) class Meta: @@ -71,15 +78,18 @@ class GameForm(forms.ModelForm): class Meta: model = Game fields = ["name", "wikidata"] + widgets = {"name": autofocus_input_widget} class PlatformForm(forms.ModelForm): class Meta: model = Platform fields = ["name", "group"] + widgets = {"name": autofocus_input_widget} class DeviceForm(forms.ModelForm): class Meta: model = Device fields = ["name", "type"] + widgets = {"name": autofocus_input_widget}