Skip to content

validate_required returns true when key exists but is empty #237

@acoustep

Description

@acoustep

I wanted to check if this is intended or not. I'm happy to try and put together a pull request if you'd like this implemented.

At the moment validate_required returns true so long as the field exists in the changeset. This differs from Elixir Ecto's implementation which from their docs says:

If the value of a field is nil or a string made only of whitespace, the changeset is marked as invalid, the field is removed from the changeset's changes, and an error is added. An error won't be added if the field already has an error.

Should Crecto follow the same process - as well as including an additional parameter for an option to trim whitespace? e.g.

validate_required :name, {trim: true}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions