Korjaa monivalintalistat (palveluyksiköt, muut jäsenet)

CheckboxSelectMultiple on RadioSelectin aliluokka, joten valintaruudut
saivat daisyUI:n radio-luokan, ja sama luokka meni myös listan
ympärillä olevalle divillä: lista kutistui pieneksi ympyräksi.

- Widget-luokkien järjestys korjattu (checkbox ennen radiota).
- Valintaryhmät renderöidään fieldset + legend -rakenteena, jokaisella
  vaihtoehdolla oma label; puhelimella yksi sarake, leveämmällä kaksi.
- Testit rakenteelle, virheen liitokselle ja näppäimistövalinnalle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-29 14:53:03 +02:00
co-authored by Claude Opus 5.5
parent 1ca03137fd
commit fe6af96a31
4 changed files with 59 additions and 2 deletions
+17
View File
@@ -126,6 +126,23 @@ class TestCreateAndEdit:
assert "Aili Alihankkija" in detail assert "Aili Alihankkija" in detail
assert "Alustava" in detail and "Normaali" in detail assert "Alustava" in detail and "Normaali" in detail
def test_choice_lists_are_checkbox_groups(
self, employee_client: Client, customer: CustomerModel, unit: ServiceUnitModel
) -> None:
html = employee_client.get("/jobs/new/").content.decode()
assert "<legend" in html and html.count('<fieldset class="fieldset"') >= 2
assert f'type="checkbox" name="service_units" value="{unit.pk}" class="checkbox"' in html
assert 'type="checkbox" name="members"' in html
assert 'class="radio"' not in html
assert 'for="id_service_units"' not in html # no label pointing at the wrapper
response = create(employee_client, customer, unit, service_units=[])
assert response.status_code == 422
page = response.content.decode()
assert 'aria-describedby="id_service_units_error"' in page
assert f'name="service_units" value="{unit.pk}" class="checkbox"' in page
assert "Valitse vähintään yksi palveluyksikkö." in page
def test_existing_tag_is_reused_ignoring_case( def test_existing_tag_is_reused_ignoring_case(
self, employee_client: Client, customer: CustomerModel, unit: ServiceUnitModel self, employee_client: Client, customer: CustomerModel, unit: ServiceUnitModel
) -> None: ) -> None:
+2 -1
View File
@@ -17,10 +17,11 @@ class DaisyFormRenderer(TemplatesSetting):
field_template_name = "components/field.html" field_template_name = "components/field.html"
# First isinstance match wins: CheckboxSelectMultiple is a subclass of RadioSelect.
_WIDGET_CLASSES: list[tuple[type[forms.Widget], str]] = [ _WIDGET_CLASSES: list[tuple[type[forms.Widget], str]] = [
(forms.CheckboxInput, "checkbox"), (forms.CheckboxInput, "checkbox"),
(forms.RadioSelect, "radio"),
(forms.CheckboxSelectMultiple, "checkbox"), (forms.CheckboxSelectMultiple, "checkbox"),
(forms.RadioSelect, "radio"),
(forms.Select, "select w-full"), (forms.Select, "select w-full"),
(forms.Textarea, "textarea w-full"), (forms.Textarea, "textarea w-full"),
(Input, "input w-full"), (Input, "input w-full"),
+25
View File
@@ -1,4 +1,28 @@
{% load i18n %}{% with widget_type=field.widget_type %} {% load i18n %}{% with widget_type=field.widget_type %}
{% if widget_type == "checkboxselectmultiple" or widget_type == "radioselect" %}
{# A group of choices: fieldset + legend, one labelled input per option (no wrapper div). #}
<fieldset class="fieldset"{% if field.help_text or field.errors %} aria-describedby="{% if field.help_text %}{{ field.auto_id }}_helptext{% endif %}{% if field.help_text and field.errors %} {% endif %}{% if field.errors %}{{ field.auto_id }}_error{% endif %}"{% endif %}>
<legend class="fieldset-legend text-sm">
{{ field.label }}{% if field.field.required %} <span aria-hidden="true">*</span><span class="sr-only">{% translate "(required)" %}</span>{% endif %}
</legend>
<div class="grid gap-1 sm:grid-cols-2">
{% for option in field %}
<label class="label cursor-pointer justify-start gap-3 text-base-content whitespace-normal" for="{{ option.id_for_label }}">
{{ option.tag }}
<span>{{ option.choice_label }}</span>
</label>
{% endfor %}
</div>
{% if field.help_text %}
<p class="label text-sm whitespace-normal" id="{{ field.auto_id }}_helptext">{{ field.help_text }}</p>
{% endif %}
{% if field.errors %}
<p class="text-error text-sm" id="{{ field.auto_id }}_error">
{% for error in field.errors %}{{ error }}{% if not forloop.last %} {% endif %}{% endfor %}
</p>
{% endif %}
</fieldset>
{% else %}
<div class="fieldset {% if field.field.widget.input_type == 'hidden' %}hidden{% endif %}"> <div class="fieldset {% if field.field.widget.input_type == 'hidden' %}hidden{% endif %}">
{% if widget_type == "checkbox" %} {% if widget_type == "checkbox" %}
<label class="label cursor-pointer justify-start gap-3 text-base-content" for="{{ field.auto_id }}"> <label class="label cursor-pointer justify-start gap-3 text-base-content" for="{{ field.auto_id }}">
@@ -20,4 +44,5 @@
</p> </p>
{% endif %} {% endif %}
</div> </div>
{% endif %}
{% endwith %} {% endwith %}
+15 -1
View File
@@ -103,7 +103,19 @@ def test_create_job_with_keyboard_and_quick_added_customer(
) )
page.fill("#id_name", "Messuosasto") page.fill("#id_name", "Messuosasto")
page.locator("input[name='service_units']").first.check() # The choice lists are real checkboxes: visible, large enough, toggled with Space.
unit_box = page.locator("input[name='service_units']").first
box = unit_box.bounding_box()
assert box is not None and box["width"] >= 16 and box["height"] >= 16
unit_box.focus()
page.keyboard.press("Space")
assert unit_box.is_checked()
member_box = page.get_by_role("group", name="Muut jäsenet").get_by_role(
"checkbox", name=admin_user.name
)
member_box.focus()
page.keyboard.press("Space")
assert member_box.is_checked()
tag = page.locator("#tag-input") tag = page.locator("#tag-input")
tag.fill("messut") tag.fill("messut")
tag.press("Enter") tag.press("Enter")
@@ -112,4 +124,6 @@ def test_create_job_with_keyboard_and_quick_added_customer(
page.wait_for_url(f"{live_server.url}/jobs/*/") page.wait_for_url(f"{live_server.url}/jobs/*/")
job = CustomerJobModel.objects.get(name="Messuosasto") job = CustomerJobModel.objects.get(name="Messuosasto")
assert job.customer.name == "Uusi Asiakas Oy" assert job.customer.name == "Uusi Asiakas Oy"
assert list(job.service_unit_links.values_list("service_unit_id", flat=True)) == [unit.pk]
assert list(job.member_links.values_list("user_id", flat=True)) == [admin_user.pk]
assert page.get_by_text("messut").count() >= 1 assert page.get_by_text("messut").count() >= 1