formex v0.2.2 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
Creates a form struct
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
Creates a form struct.
Arguments
type
- the module that implementsFormex.Type
behaviour, for example:App.ArticleType
struct
- the struct that will be used inEcto.Changeset.cast/3
, for example:%App.Article{}
params
- the parameters that will be used inEcto.Changeset.cast/3
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)