View Source Phoenix.HTML.FormData protocol (Phoenix.HTML v3.3.4)
Converts a data structure into a Phoenix.HTML.Form
struct.
Ecto integration
Phoenix provides integration of forms with Ecto changesets and data structures via the phoenix_ecto package. If a project was generated without Ecto support that dependency will need to be manually added.
Summary
Functions
Receives the given field and returns its input type (:text_input,
:select, etc). Returns nil
if the type is unknown.
Returns the HTML5 validations that would apply to the given field.
Returns the value for the given field.
Converts a data structure into a Phoenix.HTML.Form
struct.
Converts the field in the given form based on the data structure
into a list of Phoenix.HTML.Form
structs.
Types
@type t() :: term()
All the types that implement this protocol.
Functions
@spec input_type(t(), Phoenix.HTML.Form.t(), Phoenix.HTML.Form.field()) :: atom() | nil
Receives the given field and returns its input type (:text_input,
:select, etc). Returns nil
if the type is unknown.
@spec input_validations(t(), Phoenix.HTML.Form.t(), Phoenix.HTML.Form.field()) :: Keyword.t()
Returns the HTML5 validations that would apply to the given field.
@spec input_value(t(), Phoenix.HTML.Form.t(), Phoenix.HTML.Form.field()) :: term()
Returns the value for the given field.
@spec to_form(t(), Keyword.t()) :: Phoenix.HTML.Form.t()
Converts a data structure into a Phoenix.HTML.Form
struct.
The options have their meaning defined by the underlying implementation but all shared options below are expected to be implemented. All remaining options must be stored in the returned struct.
Shared options
:as
- the value to be used as the form name:id
- the ID of the form attribute. All form inputs will be prefixed by the given ID
@spec to_form(t(), Phoenix.HTML.Form.t(), Phoenix.HTML.Form.field(), Keyword.t()) :: [ Phoenix.HTML.Form.t() ]
Converts the field in the given form based on the data structure
into a list of Phoenix.HTML.Form
structs.
The options have their meaning defined by the underlying implementation but all shared options below are expected to be implemented. All remaining options must be stored in the returned struct.
Shared Options
:id
- the id to be used in the form, defaults to the concatenation of the givenfield
to the parent form id:as
- the name to be used in the form, defaults to the concatenation of the givenfield
to the parent form name:default
- the value to use if none is available:prepend
- the values to prepend when rendering. This only applies if the field value is a list and no parameters were sent through the form.:append
- the values to append when rendering. This only applies if the field value is a list and no parameters were sent through the form.:action
- The user defined action being taken by the form, such as:validate
,:save
, etc.