MishkaGervaz.Form.Types.Field.Select (MishkaGervaz v0.0.2)

Copy Markdown View Source

Single-select dropdown field type. Trims string values on sanitize.

Example

field :status, :select do
  options [{"Draft", :draft}, {"Published", :published}]
  include_nil "Any"
end

Blank choice

A select draws an empty choice ahead of its options according to the field:

  • ui placeholder set - the empty choice is labelled with it, required or not
  • required true, or a default set - no empty choice
  • otherwise - an empty choice labelled "Select..."

See MishkaGervaz.Form.Behaviours.FieldType and MishkaGervaz.Form.Types.Field.

Summary

Functions

The label of the empty choice a form select draws ahead of its options, or nil when it draws none.

Functions

prompt(field)

@spec prompt(map()) :: String.t() | nil

The label of the empty choice a form select draws ahead of its options, or nil when it draws none.

Takes the field map (ui, required and default are read from it) and returns the ui placeholder when one is set, nil for a required field or one with a default, and the translated "Select..." for any other.