PhoenixFilament.Field (PhoenixFilament v0.1.0)

Copy Markdown View Source

A plain data struct representing a form field declaration.

Each field has a name (matching an Ecto schema field), a type that determines which input component renders it, an auto-humanized label, and a keyword list of type-specific options.

Supported Field Types

  • :text_input — single-line text input
  • :textarea — multi-line text input (opts: rows)
  • :number_input — numeric input (opts: min, max, step)
  • :select — dropdown select (opts: options)
  • :checkbox — boolean checkbox
  • :toggle — boolean toggle switch
  • :date — date picker
  • :datetime — datetime picker
  • :hidden — hidden field

Common Options

  • required: true — UI hint only (shows asterisk). Real validation is in Ecto changeset.
  • label: "Custom" — overrides auto-humanized label
  • placeholder: "..." — placeholder text

Summary

Functions

Creates a :checkbox field.

Creates a :date field.

Creates a :datetime field.

Creates a :hidden field.

Creates a new Field struct. Label is auto-humanized from name unless provided in opts.

Creates a :number_input field.

Creates a :select field.

Creates a :text_input field.

Creates a :textarea field.

Creates a :toggle field.

Types

field_type()

@type field_type() ::
  :text_input
  | :textarea
  | :number_input
  | :select
  | :checkbox
  | :toggle
  | :date
  | :datetime
  | :hidden

t()

@type t() :: %PhoenixFilament.Field{
  label: String.t(),
  name: atom(),
  opts: keyword(),
  type: field_type()
}

Functions

checkbox(name, opts \\ [])

@spec checkbox(
  atom(),
  keyword()
) :: t()

Creates a :checkbox field.

date(name, opts \\ [])

@spec date(
  atom(),
  keyword()
) :: t()

Creates a :date field.

datetime(name, opts \\ [])

@spec datetime(
  atom(),
  keyword()
) :: t()

Creates a :datetime field.

hidden(name, opts \\ [])

@spec hidden(
  atom(),
  keyword()
) :: t()

Creates a :hidden field.

new(name, type, opts)

@spec new(atom(), field_type(), keyword()) :: t()

Creates a new Field struct. Label is auto-humanized from name unless provided in opts.

number_input(name, opts \\ [])

@spec number_input(
  atom(),
  keyword()
) :: t()

Creates a :number_input field.

select(name, opts \\ [])

@spec select(
  atom(),
  keyword()
) :: t()

Creates a :select field.

text_input(name, opts \\ [])

@spec text_input(
  atom(),
  keyword()
) :: t()

Creates a :text_input field.

textarea(name, opts \\ [])

@spec textarea(
  atom(),
  keyword()
) :: t()

Creates a :textarea field.

toggle(name, opts \\ [])

@spec toggle(
  atom(),
  keyword()
) :: t()

Creates a :toggle field.