formex v0.4.11 Formex.Builder
The form builder to be used in a controller. Imported by Formex.Controller
.
Example:
form = create_form(App.ArticleType, %Article{})
render(conn, "new.html", form: form)
Summary
Functions
Creates a form struct
Functions
create_form(type, struct, params \\ %{}, opts \\ [], model \\ nil)
create_form(module, Ecto.Schema.t, Map.t, List.t, module) :: Formex.Form.t
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
opts
- some additional data. Accessible byform.opts
. Example:Set current logged user
form = create_form(TransferType, %Transfer{}, %{}, user: user)
Filter select options that belongs to this user
def build_form(form) do form |> add(:user_account_id, SelectAssoc, query: fn query -> query |> Account.by_user(form.opts[:user]) end end
model
- optional model in case ifstruct
is nil. Used byFormex.Type.add/4