Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
benrom opened this issue Jun 27, 2018 · 0 comments
Open

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

benrom opened this issue Jun 27, 2018 · 0 comments

Comments

@benrom
Copy link
Contributor

benrom commented Jun 27, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant