formex v0.1.4 Formex.Field

Summary

Functions

Defines the Formex.Field struct

Types

t()
t() :: %Formex.Field{data: term, label: term, name: term, opts: term, required: term, type: term, value: term}

Functions

__struct__()

Defines the Formex.Field struct.

  • :name - a field name, for example: :title
  • :type - type of field that in most cases will be name of function from Phoenix.HTML.Form
  • :value - the value from struct/params
  • :required - is field required?
  • :label - the text label
  • :data - additional data used by particular field type (eg. :select_assoc stores here data for <option>’s)
  • :opts - options
create_field(form, type, name, opts)

Creates a new field.

type is, in most cases, the name of function from Phoenix.HTML.Form. For now the only exception is the :select_assoc

Custom types

  • :select_assoc - creates standard :select, but also downloads list of options from Repo. Example of use for Article with one Category:

    schema "articles" do
      belongs_to :category, App.Category
    end
    form
    |> add(:select_assoc, :category_id, label: "Category")

    Formex will find out that :category_id refers to App.Category schema and download all rows from Repo ordered by name. It assumes that Category has field called name

Options

  • :label
  • :required - defaults to true
  • :phoenix_opts - options that will be passed to Phoenix.HTML.Form, for example:

    form
    |> add(:textarea, :content, phoenix_opts: [
      rows: 4
    ])