MishkaGervaz.Form.Entities.Field (MishkaGervaz v0.0.1-alpha.2)

Copy Markdown View Source

Form field — name, type, validation, access predicates, and an optional ui sub-entity for label / placeholder / styling plus an optional preload sub-entity for relation field eager-loading.

Field type is either a built-in token (:text, :textarea, :select, :relation, :nested, etc.) or a module implementing MishkaGervaz.Form.Behaviours.FieldType. When omitted, type is inferred from the matching Ash attribute. Visibility (visible / restricted) follows the standard predicate convention shared with groups, headers, footers, and notices.

Example

fields do
  field :title, :text do
    required true
    position :first

    ui do
      label "Title"
      placeholder "Enter title..."
      span 2
    end
  end

  field :user_id, :relation do
    mode :search
    display_field :email
    search_field :email

    preload do
      always [:role]
    end
  end
end

See MishkaGervaz.Form.Dsl.Fields for the surrounding section, MishkaGervaz.Form.Entities.Field.Ui for the ui sub-entity, MishkaGervaz.Form.Entities.Field.Preload for the preload sub-entity, MishkaGervaz.Form.Entities.NestedField for sub-field declarations inside a :nested field, and MishkaGervaz.Form.Behaviours.FieldType for custom field types.

Summary

Functions

Transform the field after DSL compilation.

Types

position()

@type position() :: integer() | :first | :last | {:before, atom()} | {:after, atom()}

t()

@type t() :: %MishkaGervaz.Form.Entities.Field{
  __identifier__: term(),
  __spark_metadata__: map() | nil,
  _nested_field_entities: term(),
  add_label: String.t() | nil,
  apply: (any(), any(), map() -> any()) | nil,
  array_fields: list(),
  auto_fields: boolean(),
  default: any(),
  depends_on: atom() | nil,
  derive_value: (struct() -> any()) | nil,
  display_field:
    atom() | (struct() -> String.t()) | (struct(), map() -> String.t()) | nil,
  format: (any() -> any()) | (map(), map(), any() -> any()) | nil,
  include_nil: boolean() | String.t() | (-> String.t()),
  load: (any(), map() -> any()) | nil,
  load_action: atom() | {atom(), atom()} | nil,
  max: integer() | nil,
  min: integer() | nil,
  min_chars: integer() | nil,
  mode: :static | :load_more | :search | :search_multi,
  name: atom(),
  nested_fields: list(),
  options: list() | (-> list()) | nil,
  options_source: {module(), atom(), atom()} | nil,
  page_size: pos_integer(),
  position: position() | nil,
  preload: MishkaGervaz.Form.Entities.Field.Preload.t() | nil,
  readonly: boolean() | (map() -> boolean()),
  remove_label: String.t() | nil,
  render:
    (struct() -> Phoenix.LiveView.Rendered.t())
    | (struct(), map() -> Phoenix.LiveView.Rendered.t())
    | nil,
  required: boolean(),
  resource: module() | nil,
  restricted: boolean() | (map() -> boolean()),
  search_field: atom() | nil,
  show_on: :create | :update | nil,
  source: atom() | nil,
  type: atom() | module(),
  type_module: module() | nil,
  ui: MishkaGervaz.Form.Entities.Field.Ui.t() | nil,
  value_field: atom() | nil,
  virtual: boolean(),
  visible: boolean() | (map() -> boolean())
}

Functions

transform(field)

Transform the field after DSL compilation.

Sets defaults, resolves the type_module, and extracts nested entities.