formex v0.3.2 Formex.View

Helper functions for templating.

Example of use:

<%= formex_form_for @form, @action, fn f -> %>
  <%= if @form.changeset.action 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/4:

    <%= formex_form_for @form, @action, [
        class: "form-horizontal",
        template: Formex.Template.BootstrapHorizontal
      ], fn f -> %>
      ...
    <% end %>
  • formex_rows/2:

    <%= formex_rows f, template: Formex.Template.BootstrapHorizontal %>
  • formex_row/3:

    <%= formex_row f, :name, template: Formex.Template.BootstrapHorizontal %>

Summary

Functions

formex_form_for(form, action, options \\ [], fun)
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.form_for/4

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

formex_row(form, item_name, options \\ [])

Generates a row

Example of use:

<%= formex_row f, :title %>
<%= formex_row f, :content %>
<%= formex_row f, :category_id %>

Options

formex_rows(form, options \\ [])

Generates all formex_row/2s at once

Options