Skip to content

Commit 8c84da4

Browse files
committed
Add checkbox group example to README
Shows how to build checkbox and radio groups using loops and existing primitives, keeping control of the HTML structure.
1 parent 81ad323 commit 8c84da4

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,19 @@ 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.
410+
fieldset do
411+
legend { "Select your roles" }
412+
Role.pluck(:id, :name).each do |id, name|
413+
label do
414+
Field(:role_ids).checkbox(name: "user[role_ids][]", value: id)
415+
plain " #{name}"
416+
end
417+
end
418+
end
419+
407420
render button { "Submit" }
408421
end
409422
end

0 commit comments

Comments
 (0)