formex v0.1.4 Formex.Type behaviour
In order to create a form, you need to create the Type file. It’s similar to Symfony’s way of creating forms.
Example:
defmodule App.ArticleType do
use Formex.Type
def build_form(form) do
form
|> add(:text_input, :title, label: "Title")
|> add(:textarea, :content, label: "Content", phoenix_opts: [
rows: 4
])
|> add(:checkbox, :hidden, label: "Is hidden", required: false)
|> add(:select_assoc, :category_id, label: "Category", phoenix_opts: [
prompt: "Choose category"
])
end
# optional
def changeset_after_create_callback(changeset) do
# do extra validation and return a new changeset
changeset
end
end
Summary
Callbacks
Adds a field to a form. More: Formex.Field.create_field/4
In this callback you have to add fields to a Form
Callback that will be called after changeset creation. In this function you can for example add extra validation to your changeset
Callbacks
Adds a field to a form. More: Formex.Field.create_field/4
In this callback you have to add fields to a Form.
changeset_after_create_callback(changeset)
changeset_after_create_callback(changeset :: Ecto.Changeset.t) :: Ecto.Changeset.t
Callback that will be called after changeset creation. In this function you can for example add extra validation to your changeset.