Packages
phoenix_html
4.3.0
4.3.0
4.2.1
4.2.0
4.1.1
4.1.0
4.0.0
3.3.4
3.3.3
3.3.2
3.3.1
3.3.0
3.2.0
3.1.0
3.0.4
3.0.3
retired
3.0.2
retired
3.0.1
retired
3.0.0
retired
2.14.3
2.14.2
2.14.1
2.14.0
2.13.4
2.13.3
2.13.2
2.13.1
2.13.0
2.12.0
2.11.2
2.11.1
2.11.0
2.10.5
2.10.4
2.10.3
2.10.2
2.10.1
2.10.0
2.9.3
2.9.2
2.9.1
2.9.0
2.8.0
2.7.0
2.7.0-dev
2.6.2
2.6.1
2.6.0
2.5.1
2.5.0
2.4.0
2.4.0-dev
2.3.1
2.3.0
2.2.0
2.1.2
2.1.1
2.1.0
2.0.1
2.0.0
2.0.0-dev
1.4.0
1.3.0
1.2.1
1.2.0
1.1.0
1.0.1
1.0.0
Phoenix view functions for working with HTML templates
Current section
Files
Jump to
Current section
Files
lib/phoenix_html/form_field.ex
defmodule Phoenix.HTML.FormField do
@moduledoc """
The struct returned by `form[field]`.
It has the following fields:
* `:errors` - a list of errors belonging to the field
* `:field` - the field name as an atom or a string
* `:form` - the parent `form` struct
* `:id` - the `id` to be used as form input as a string
* `:name` - the `name` to be used as form input as a string
* `:value` - the value for the input
This struct also implements the `Access` behaviour,
but raises if you try to access a field that is not defined.
"""
@type t :: %__MODULE__{
id: String.t(),
name: String.t(),
errors: [term],
field: Phoenix.HTML.Form.field(),
form: Phoenix.HTML.Form.t(),
value: term
}
@enforce_keys [:id, :name, :errors, :field, :form, :value]
defstruct [:id, :name, :errors, :field, :form, :value]
@behaviour Access
@impl true
def fetch(struct, key) do
{:ok, Map.fetch!(struct, key)}
end
@impl true
def get_and_update(struct, key, fun) do
Map.get_and_update!(struct, key, fun)
end
@impl true
def pop(struct, _key) do
raise ArgumentError, "cannot pop keys from #{inspect(struct)}"
end
end