MishkaGervaz.Form.Types.Field.Nested (MishkaGervaz v0.0.6)

Copy Markdown View Source

Nested / embedded form field type, used for inputs_for and constrained-map columns.

Example

field :seo_tags, :nested do
  ui do
    add_label "+ Add SEO tag"
    remove_label "Remove"
  end

  nested_field :tag do
    ui do placeholder "meta, link, script" end
  end

  nested_field :content, :textarea do
    ui do rows 3 end
  end
end

Sub-field values are cast on the way in

parse_params/2 casts each row by its sub-field's declared type before the value reaches the changeset:

Sub-field typeCast
:checkbox, :toggle"true" / "on" / "1" to true; "false" / "off" / "0" / "" to false
:numberinteger, then float
:key_mapeach declared key cast, then blanks dropped
:key_listeach row cast and pruned, then empty rows dropped

Anything it cannot make sense of is left exactly as it came, and a value that is already the right type passes through untouched.

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