Files
sure/app/components/DS/toggle.html.erb
Guillem Arias Fauste 4bb326fee5 docs(ds-toggle): warn against external hidden_field_tag with same name (#1925)
DS::Toggle already renders a paired hidden field for the off-state
value. Adding an external `hidden_field_tag` with the same `name` in a
caller view causes ID/label collisions (the auto-generated id matches
the checkbox id, so `<label for=...>` targets the hidden field) and
sends duplicate params.

Inline ERB comment so the warning surfaces wherever the component is
read or copied.
2026-05-23 08:53:56 +02:00

10 lines
751 B
Plaintext

<div class="relative inline-block select-none">
<%# Paired hidden field carries the off-state value when the checkbox is unchecked. Do NOT add an external `hidden_field_tag` with the same `name` in the caller view — it causes ID/label collisions and duplicate params. %>
<%= hidden_field_tag name, unchecked_value, id: nil %>
<%# `role="switch"` upgrades the underlying checkbox so AT users hear
"switch, on" / "switch, off" instead of "checkbox, checked". The
visual already reads as a switch — semantics now match. %>
<%= check_box_tag name, checked_value, checked, class: "sr-only peer", disabled: disabled, id: id, role: "switch", **opts %>
<%= label_tag name, "&nbsp;".html_safe, class: label_classes, for: id %>
</div>