Formex v0.6.7 Formex.Template behaviour
Use this module to create a custom form template.
Usage:
defmodule App.FormTemplate.SemanticUI do
use Formex.Template
def generate_row(form, field, _options \\ []) do
# code that produces a Phoenix.HTML.safe
# you can use here render_phoenix_input/2, has_error/2
end
end
If you want to create a several version of template (for example vertical and horizontal, as is already done with Bootstrap), you can move a common code to another module.
Example:
defmodule App.FormTemplate.SemanticUIVertical do
use Formex.Template, :main # note the :main argument
import App.FormTemplate.SemanticUI
def generate_row(form, field, _options \\ []) do
# code that produces a Phoenix.HTML.safe
end
end
defmodule App.FormTemplate.SemanticUIHorizontal do
use Formex.Template, :main # note the :main argument
import App.FormTemplate.SemanticUI
def generate_row(form, field, _options \\ []) do
# code that produces a Phoenix.HTML.safe
end
end
defmodule App.FormTemplate.SemanticUI do
use Formex.Template, :helper # note the :helper argument
# a common code for both versions
# you can use here render_phoenix_input/2, has_error/2
end
See the source code of templates for more examples.
Summary
Functions
Adds a CSS class to the :phoenix_opts
keyword
Formats error using
Phoenix.HTML.Format.text_to_html/2
Returns list of errors
Checks if given field has an error
Runs function from Phoenix.HTML.Form
defined in a Field.type
or Button.type
Callbacks
Generates a HTML for a field
Functions
Adds a CSS class to the :phoenix_opts
keyword
Formats error using
Phoenix.HTML.Format.text_to_html/2
Returns list of errors
Checks if given field has an error
Runs function from Phoenix.HTML.Form
defined in a Field.type
or Button.type
Callbacks
generate_input(form :: Formex.Form.t, field_or_button :: any) :: Phoenix.HTML.safe
generate_label(form :: Formex.Form.t, field :: Formex.Field.t, class :: String.t) :: Phoenix.HTML.safe
generate_row(form :: Formex.Form.t, field :: Formex.Field.t, options :: Keyword.t) :: Phoenix.HTML.safe
Generates a HTML for a field.
Arguments
options
- any options that you want to use inside a form template. It can be set by:template_options
inside aFormex.View
functions, or in the:formex
config. For example,Formex.Template.BootstrapHorizontal
uses options that stores columns sizes.