ex_admin icon indicating copy to clipboard operation
ex_admin copied to clipboard

Required fields for forms not taking into account custom Changesets

Open benrom opened this issue 7 years ago • 0 comments

I have registered two changesets for a user account: one for creation with a required :password field, and one for update where the virtual :password field is not required (if no new password is set, I just dismiss this field and just update the other fields).

In the resulting form, the :password field is always set as required when editing an existing account, even though its associated changeset does not list it in validate_required().

If I change the default changeset method to remove the required field, I can see my form not showing password as required. Though it breaks the creation form where I wanted it to be required.

After a quick search through the code, the issue could lie around here:

required_list =
      cond do
        Map.get(res, :__struct__, false) ->
          res.__struct__.changeset(res).required

        true ->
          []
      end

It should use instead the custom changeset functions if they were defined, using changeset() only as a fallback.

benrom avatar Jun 27 '18 14:06 benrom