formex v0.1.4 Formex.Builder

The form builder.

Example:

form = create_form(App.ArticleType, %Article{})
render(conn, "new.html", form: form)
App.ArticleType
|> create_form(%Article{}, article_params)
|> insert_form_data
|> case do
  {:ok, _article} ->
    # ...
  {:error, form} ->
    # ...
end

Summary

Functions

Invokes Repo.insert. In case of :error returns {:error, form} (with new form.changeset value) instead of {:error, changeset} (as Ecto does)

Invokes Repo.update. In case of :error returns {:error, form} (with new form.changeset value) instead of {:error, changeset} (as Ecto does)

Functions

create_form(type, struct, params \\ %{})
create_form(module, Ecto.Schema.t, Map.t) :: Formex.Form.t

Creates a form struct.

Arguments

  • type - the module that implements Formex.Type, for example: App.ArticleType
  • struct - the struct that will be used in Ecto.Changeset.cast, for example: %App.Article{}
  • params - params that will be used in Ecto.Changeset.cast
insert_form_data(form)
insert_form_data(Formex.Form.t) ::
  {:ok, Ecto.Schema.t} |
  {:error, Formex.Form.t}

Invokes Repo.insert. In case of :error returns {:error, form} (with new form.changeset value) instead of {:error, changeset} (as Ecto does)

update_form_data(form)
update_form_data(Formex.Form.t) ::
  {:ok, Ecto.Schema.t} |
  {:error, Formex.Form.t}

Invokes Repo.update. In case of :error returns {:error, form} (with new form.changeset value) instead of {:error, changeset} (as Ecto does)