Skip to content

Latest commit

 

History

History
78 lines (55 loc) · 2.36 KB

UPGRADE.md

File metadata and controls

78 lines (55 loc) · 2.36 KB

Upgrade from 0.5 to 0.6

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.

Upgrade from 0.4 to 0.5

Ecto

Ecto related code has been moved to formex_ecto package. Just install it and it should work. Except the validation, which is described below.

Validation

  • 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:

  1. Use any available validator and:
    • move your validation from changeset_after_create_callback to :validation option of Formex.Type.add
    • rewrite translation for error messages, if had any
  2. Use Formex.Ecto.ChangesetValidator (from formex_ecto package) and:
    • move your validation from changeset_after_create_callback to a new callback - changeset_validation from Formex.Ecto.ChangesetValidator.

The second option is faster.

And remember, :required is no longer used for validation.

Templating

replace

<%= if @form.changeset.action do %>
  oops, error
<% end %>

with

<%= if @form.submitted? do %>
  oops, error
<% end %>

Custom fields

Formex.CustomField.SelectAssoc rename to Formex.Ecto.CustomField.SelectAssoc

web.ex

def model do
  quote do
    use Formex.Ecto.Schema # renamed from Formex.Schema
  end
end