mirror of
https://github.com/we-promise/sure.git
synced 2026-05-25 13:34:58 +00:00
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.
10 lines
751 B
Plaintext
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, " ".html_safe, class: label_classes, for: id %>
|
|
</div>
|