Formex v0.6.7 Formex.View
Helper functions for templating.
Example of use:
<%= formex_form_for @form, @action, fn f -> %>
<%= if @form.submitted? do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<%= formex_rows f %>
<div class="form-group">
<%= submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>
Changing a form template
You can change the template globally or in the specific form/field.
config
config :formex, template: Formex.Template.BootstrapHorizontal template_options: [ # options used by this template left_column: "col-xs-2", right_column: "col-xs-10" ]
-
<%= formex_form_for @form, @action, [ class: "form-horizontal", template: Formex.Template.BootstrapHorizontal ], fn f -> %> ... <% end %>
-
<%= formex_rows f, template: Formex.Template.BootstrapHorizontal %>
-
<%= formex_row f, :name, template: Formex.Template.BootstrapHorizontal %>
Summary
Functions
Works similar to a Phoenix.HTML.Form
Generates an input, used by formex_row/3
Generates a label, used by formex_row/3
Generates a row using formex_label/3
and formex_input/3
Generates all formex_row/2
s at once
Functions
formex_form_for(form :: Formex.Form.t, action :: String.t, options :: Keyword.t, fun :: (Formex.t -> Phoenix.HTML.unsafe)) :: Phoenix.HTML.safe
Works similar to a Phoenix.HTML.Form
In the callback function the first argument is Formex.Form.t/0
instead of a
Phoenix.HTML.Form.t/0
.
This argument contains the Phoenix.HTML.Form.t/0
under a :phoenix_form
key
Options
In options
argument you are passing together options for Formex.View
and for Phoenix.HTML
.
Formex options
template
- a form template that implementsFormex.Template
, for example:Formex.Template.BootstrapHorizontal
template_options
- additional options, supported by the template
Phoenix options
Options not mentioned before will be passed to a Phoenix.HTML.Form function. Options below are already set by Formex and can be overriden.
as
- form name, defaults to struct namemethod
- method, defaults to:post
For rest of options, see Phoenix.HTML.Form docs.
formex_input(Formex.Form.t, Atom.t, Keyword.t) :: Phoenix.HTML.safe
Generates an input, used by formex_row/3
Example of use:
<div>
<%= formex_label f, :title %>
<%= formex_input f, :title %>
</div>
<%= formex_input f, :some_hidden_field %>
Options
template
- a form template that implementsFormex.Template
, for example:Formex.Template.BootstrapHorizontal
formex_label(Formex.Form.t, Atom.t, Keyword.t) :: Phoenix.HTML.safe
Generates a label, used by formex_row/3
Example of use:
<div>
<%= formex_label f, :title %>
<%= formex_input f, :title %>
</div>
Options
template
- a form template that implementsFormex.Template
, for example:Formex.Template.BootstrapHorizontal
formex_row(Formex.Form.t, Atom.t, Keyword.t) :: Phoenix.HTML.safe
Generates a row using formex_label/3
and formex_input/3
Example of use:
<%= formex_row f, :title %>
<%= formex_row f, :content %>
<%= formex_row f, :category_id %>
Options
template
- a form template that implementsFormex.Template
, for example:Formex.Template.BootstrapHorizontal
template_options
- additional options, supported by the template
Generates all formex_row/2
s at once
Options
template
- a form template that implementsFormex.Template
, for example:Formex.Template.BootstrapHorizontal
template_options
- additional options, supported by the template