Skip to content

feat: support dependent enum selectors - #29

Open
NachoCP-eng wants to merge 2 commits into
mainfrom
feat/dependent-enum-selectors
Open

feat: support dependent enum selectors#29
NachoCP-eng wants to merge 2 commits into
mainfrom
feat/dependent-enum-selectors

Conversation

@NachoCP-eng

@NachoCP-eng NachoCP-eng commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

What

Adds two optional enum capabilities while preserving the existing default behavior:

  • multiple: false renders a native single-value select.
  • depends_on: filters a multi-value enum by the selected value of another enum.

Dependent choices use the explicit tuple [label, submitted_value, parent_value]. Existing string lists and [label, value] pairs continue to behave exactly as before.

How it works

  1. DataDrip::Types::Enum stores only two pieces of presentation metadata: cardinality and the optional parent attribute.
  2. SchematizedOptions removes those keys before calling ActiveModel, so they do not leak into ActiveModel type options.
  3. The helper renders either the existing searchable checkbox list or a native select. Dependent rows carry their parent value as data, not executable code.
  4. The existing Stimulus controller listens for a parent enum change, hides and unchecks nonmatching rows, selects the matching choices and synchronizes the same comma-separated hidden field used today.
  5. Server-side enum validation remains an allowlist over declared submitted values. Cross-field business rules remain the owning backfill responsibility and are documented explicitly.

Scope review

This deliberately does not add remote option endpoints, arbitrary callbacks receiving request state, new persistence, controllers, routes or database changes. It extends the existing enum type/helper/controller only.

The dependency lookup is scoped to the nearest form, and select-all state is calculated only from currently visible choices.

Compatibility

  • Existing enums remain multi-select and preselect all choices by default.
  • Existing string choices and label/value pairs are unchanged.
  • Scripts and backfills share the same enum type and validation path.

Verification

  • Full suite: 295 examples, 0 failures.
  • RuboCop: 83 files, no offenses.
  • README and CHANGELOG document the public API and server-side validation responsibility.

Implemented-with: factorial-pr
Implemented-with: factorial-pr
@NachoCP-eng
NachoCP-eng marked this pull request as ready for review August 20, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant