Aurora. Uix. Templates. Basic. Renderers. MultiSelect
(Aurora UIX v0.1.6-rc.4)
Copy Markdown
Renders a multi-value select (html_type: :select with data.select.multiple) as a list of
checkboxes over its options.
This is the scalar counterpart of Aurora.Uix.Templates.Basic.Renderers.ManyToMany, and it exists
for the same reason: a <select multiple> needs a modifier-key gesture that is undiscoverable and
unusable on touch, conveys state only through a background colour, and has nowhere to host bulk
controls. The wire format is identical -- every box shares the parent[field][] name, so only
checked values are submitted, exactly as only selected options are.
Options come straight from the parsed field (data.select.opts) through
Aurora.Uix.Templates.Basic.Helpers.get_select_options/1, so both backends reach this renderer
unchanged: Ctx parses {:array, Ecto.Enum} and Ash parses an array attribute whose item type
carries a one_of constraint (or is an Ash.Type.Enum module) into the same shape.
Key Features
:formrenders one checkbox per option; the checked boxes are the current value.- Submits in the same POST as the parent, under
parent[field][]. - Emits a hidden empty-value sentinel so that de-selecting everything still submits the key, which is what makes clearing the last value possible at all.
- Ships
:default_toggle_all, a tri-state checkbox beside the label: checked when every option is selected, unchecked when none is, and a dash when only some are. Clicking a checked toggle clears the selection; clicking it in either other state selects everything. - Registers three action groups through
Aurora.Uix.Action--label(holding the toggle),headerandfooter, the latter two empty -- so a host adds, replaces or removes controls in any of the three strips from the layout DSL field options. :showrenders only the selected options as a plain, read-only list, with thedt("No options to show")empty state.
Key Constraints
- The library is transport-only for writes: it renders the input name and forwards the submitted list untouched, and never builds a changeset.
- Because of the sentinel, the submitted list always carries one blank entry. The host must
reject it -- an
Ecto.Enumarray otherwise fails to cast, and Ash rejects the list with "no nil values" unless the attribute or argument declaresconstraints: [nil_items?: true]. - The toggle rides the parent form's
phx-change="validate", identified by_target. It must not usephx-click: a click on a checkbox firesclickand thenchange, and the trailing change would re-validate with the pre-click selection and undo the toggle. - Hidden fields never reach this renderer --
DefaultRendererkeeps them on its generic clause, which renders them as a single<input type="hidden">.
Summary
Functions
Renders a multi-value select field.
Functions
@spec render(map()) :: Phoenix.LiveView.Rendered.t()
Renders a multi-value select field.
Parameters
assigns(map()) - LiveView assigns containing::field(map()) - Field definition with the select options in:data.:auix(map()) - Aurora UIX context with form, entity and layout configuration.
Returns
Phoenix.LiveView.Rendered.t() - Rendered multi-value select component.