Skip to content

Add Backpex.Fields.Checkgroup#1691

Open
Flo0807 wants to merge 11 commits intodevelopfrom
feature/add-checkgroup-field
Open

Add Backpex.Fields.Checkgroup#1691
Flo0807 wants to merge 11 commits intodevelopfrom
feature/add-checkgroup-field

Conversation

@Flo0807
Copy link
Copy Markdown
Collaborator

@Flo0807 Flo0807 commented Dec 5, 2025

No description provided.

@Flo0807 Flo0807 self-assigned this Dec 5, 2025
@Flo0807 Flo0807 marked this pull request as draft December 5, 2025 23:32
@Flo0807 Flo0807 added the feature New feature label Dec 5, 2025
@Flo0807 Flo0807 requested a review from Copilot February 20, 2026 12:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a new Backpex.Fields.Checkgroup field type for handling multiple checkboxes with predefined options. This field provides a simpler, more straightforward alternative to MultiSelect for cases where users need to select multiple values from a flat list of options without search functionality or grouping.

Changes:

  • Adds new Backpex.Fields.Checkgroup field module with render_value and render_form implementations
  • Extends HTML form component to support "checkgroup" input type with multiple checkboxes
  • Updates demo to replace MultiSelect with Checkgroup for user permissions, including schema and migration changes

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/backpex/fields/checkgroup.ex New field module implementing checkbox group functionality with options support
lib/backpex/html/form.ex Adds "checkgroup" input type with hidden input for empty arrays and accessible checkbox rendering
demo/priv/repo/migrations/20251205230743_set_default_for_permissions.exs Sets database default to empty array and updates existing NULL values for permissions field
demo/lib/demo_web/live/user_live.ex Replaces MultiSelect with Checkgroup for permissions field with simplified flat options
demo/lib/demo/user.ex Adds Ecto schema default value for permissions field

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/backpex/fields/checkgroup.ex Outdated
Comment thread lib/backpex/html/form.ex Outdated
Flo0807 added 10 commits April 22, 2026 15:05
The `alias Backpex.HTML` is already injected by `use Backpex.Field`
via BackpexWeb's field helpers. Drop the duplicate alias; sibling
fields like Select and Text rely on the injected alias as well.
Compare option values and the current selection as strings, matching
the coercion already performed by Checkgroup.get_labels/2. Without
this, atom or integer option values never register as checked when
the wrapped value is stored as strings (or vice versa).
Wrap the checkgroup inputs in a <fieldset> with a <legend> so the
group has a native accessible name. Remove the `{@rest}` spread on
individual checkboxes: group-level attributes such as
aria-labelledby or required must not land on every box.

Nest the checkbox input inside its <label> for a robust implicit
association (no more stale `for=` pair) and add `min-h-11` to
satisfy the 44px touch-target requirement.

Drop `aria-labelledby` from Checkgroup.render_form/1 — the <legend>
now provides the accessible name natively.
Each checkbox now advertises its invalid state via aria-invalid when
the field has errors, and points at the help text via
aria-describedby when one is provided. Give the help_text component
an optional `id` attribute so we can target it stably as
`<id>-help`.
Add a `readonly` option to Checkgroup's config schema, pass it
through Checkgroup.render_form/1 to BackpexForm.input, and honor it
on each checkbox via `disabled={@readonly}`. Matches the convention
already used by the Text and Select fields.

Because `{@rest}` is no longer spread onto individual checkboxes,
the checkgroup clause pulls `readonly` out of `@rest` explicitly.
Call out in the moduledoc that users must set `default: []` on both
the Ecto schema field and the SQL column, otherwise unchecking all
boxes will persist NULL instead of an empty array — a consequence of
Ecto's `filter_empty_values/3` treating the hidden sentinel input's
scalar "" as empty.
List Backpex.Fields.Checkgroup alongside the other built-in field
types so it's discoverable from the fields guide.
The `min-h-11` touch target already enforces 44px rows, so the
additional `space-y-2` on the options wrapper produced ~52px rows
which felt too airy. Drop the extra gap and let the min-height
carry the rhythm.
The 44px min-height is a mobile touch-target requirement; on
desktop it makes rows feel overly tall. Drop the min-height at
the `md:` breakpoint and up.
@Flo0807 Flo0807 marked this pull request as ready for review April 22, 2026 13:36
@Flo0807 Flo0807 requested a review from pehbehbeh April 22, 2026 13:36
Comment on lines +12 to +14
def down do
execute "ALTER TABLE users ALTER COLUMN permissions DROP DEFAULT"
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants