Skip to content

Required fields for forms not taking into account custom Changesets #443

Description

@benrom

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions