You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make radios/checkboxes renderable Phlex components
radios/checkboxes now return Phlex components instead of a Choices
enumerable. Without a block they render default label+input markup;
with a block they yield each Choice for custom layout. Kit auto-renders
them as one-liners.
Reorganize into Choices module: Choice::Choice holds per-option state,
Choice::Mapper (renamed from OptionMapper) maps args to (value, text)
pairs. Choice exposes a unified `input` method instead of separate
radio/checkbox methods — the type is set at construction.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,12 @@
2
2
3
3
### Added
4
4
5
-
-**Radio and checkbox groups** via `field(:plan).radios(...)` and `field(:roles).checkboxes(...)`.
6
-
Accepts the same option formats as `select`. Each iteration yields a `Choice` with
7
-
`.radio`, `.checkbox`, `.label`, `.value`, `.text`. Auto-detects Rails enums when called
8
-
with no arguments — options are generated from `Model.defined_enums` with humanized labels.
5
+
-**Radio and checkbox groups** via `Field(:plan).radios(...)` and `Field(:roles).checkboxes(...)`.
6
+
Now return renderable Phlex components (like `input`, `select`) so they work as one-liners
7
+
via Kit. Without a block, renders default `<label><input> Text</label>` markup per choice.
8
+
With a block, yields each `Choice` for custom markup — choice methods (`.input`,
9
+
`.label`) render directly into the component's output. Accepts the same option formats as
10
+
`select`. Auto-detects Rails enums when called with no arguments.
9
11
`choice.label` without a block defaults to rendering `choice.text`.
10
12
-**Hash options** for `select`, `radios`, and `checkboxes` — e.g. `radios(1 => "Basic", 2 => "Pro")`.
11
13
-**Radio component** with `field(:gender).radio("male")` API. Automatically handles name, value, and checked state. Each radio gets a unique DOM id based on its value (e.g. `user_gender_male`).
Copy file name to clipboardExpand all lines: README.md
+63-13Lines changed: 63 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -222,6 +222,40 @@ Then render it from Erb.
222
222
223
223
Much better!
224
224
225
+
### Customizing radios and checkboxes
226
+
227
+
`radios` and `checkboxes` render sensible defaults out of the box, but you can subclass them to match your design system. Override `view_template` to change the default markup — the block form still works for one-off customizations.
Now every `Field(:status).radios` in your app gets the custom markup. Individual forms can still pass a block for one-off layouts.
258
+
225
259
## Namespaces & Collections
226
260
227
261
Superform uses a different syntax for namespacing and collections than Rails, which can be a bit confusing since the same terminology is used but the application is slightly different.
@@ -370,7 +404,7 @@ class JobPostingForm < Components::Form
370
404
end
371
405
372
406
# ActiveRecord relations work as select options too.
373
-
#OptionMapper uses the primary key as value and joins remaining
407
+
#Choice::Mapper uses the primary key as value and joins remaining
0 commit comments