There is only one big (maybe) change.
Prior to formex 0.6.0, when you will manually remove a input tag
in browser and send a form, then value for that input will be unchanged.
Since formex 0.6.0, that value will be set to ""
.
If you didn't do any JS hacks in your form, then you don't have to care about that change.
Ecto related code has been moved to formex_ecto package. Just install it and it should work. Except the validation, which is described below.
- the
:required
option NO LONGER VALIDATES PRESENCE OF VALUE. It's now used only in template, e.g. to generate an asterisk. Validation can be performed via:validation
option.
Why? For example, you have form for client, and client can be individual or business.
A checkbox + JS controls which fields (individual and business related) are currently
displayed. In previous version of formex you should disable :required
option of that fields
(form would always be invalid) and perform validation manually in changeset.
But then, asterisk at the field will not be displayed, although it's required.
The above change solves that problem. Now it works in the same way as in Symfony
- you must use an external validator to validate required fields.
See list of available libraries
You have two options to migrate validations:
- Use any available validator and:
- move your validation from
changeset_after_create_callback
to:validation
option ofFormex.Type.add
- rewrite translation for error messages, if had any
- move your validation from
- Use
Formex.Ecto.ChangesetValidator
(fromformex_ecto
package) and:- move your validation from
changeset_after_create_callback
to a new callback -changeset_validation
fromFormex.Ecto.ChangesetValidator
.
- move your validation from
The second option is faster.
And remember, :required
is no longer used for validation.
replace
<%= if @form.changeset.action do %>
oops, error
<% end %>
with
<%= if @form.submitted? do %>
oops, error
<% end %>
Formex.CustomField.SelectAssoc
rename to Formex.Ecto.CustomField.SelectAssoc
def model do
quote do
use Formex.Ecto.Schema # renamed from Formex.Schema
end
end