Phoenix.HTML.FormData protocol (Phoenix.HTML v4.3.0)
View SourceA protocol for converting data structure into a Phoenix.HTML.Form struct.
The functions here are rarely invoked directly by application developers.
Rather, this is low-level entrypoint used by libraries. For working
with forms in your Phoenix application, you likely want to use
Phoenix.Component.to_form/2
instead.
Summary
Functions
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_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 givenfieldto the parent form id:as- the name to be used in the form, defaults to the concatenation of the givenfieldto 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.