Skip to content

Commit d072ab1

Browse files
committed
Update checkbox group example to use collections
Use Field(:role_ids).collection instead of manual name construction. The collection handles naming and data binding; the user controls markup.
1 parent 8c84da4 commit d072ab1

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,14 @@ class SignupForm < Components::Form
404404
Field(:agreement).checkbox(checked: true)
405405
end
406406

407-
# Checkbox and radio groups are just loops. This keeps you in control
408-
# of the HTML structure — labels wrapping inputs, labels alongside
409-
# inputs, fieldsets, etc.
407+
# Checkbox and radio groups use collections. The collection handles
408+
# naming (including []) and data binding. You control the HTML structure.
410409
fieldset do
411410
legend { "Select your roles" }
412-
Role.pluck(:id, :name).each do |id, name|
411+
Field(:role_ids).collection.each do |role|
413412
label do
414-
Field(:role_ids).checkbox(name: "user[role_ids][]", value: id)
415-
plain " #{name}"
413+
role.checkbox
414+
plain " #{role.value}"
416415
end
417416
end
418417
end

0 commit comments

Comments
 (0)