Add in required validation, replicating Ecto's validate_required functionality
- Dominant language
- Elixir
- Stars
- 2.5k
- Forks
- 422
- Avg merge
- 23h 26m
- Merged PRs (30d)
- 46
Description
**Is your feature request related to a problem? Please describe.**
Default validation of attributes marked with `allow_nil?: false`, will separately mark the error as "required", which is quite clear for users when using a form and not filling in a value.
The closest we have is present/2, which has 2 issues:
- default error message is it needs to be "present", which if directly displayed on the form, can be a bit unclear to the user of what they need to do. this requires us to override the default error message
- If you need to mark more than 1 field as required, then you need to separately use present/2 for each attribute. If you pass in a list, then each attribute, on a form, will be marked as invalid if only 1 doesn't have a value.
**Describe the solution you'd like**
Create a require/2 function that replicates the behavior we have in Ecto's validate_required
**Describe alternatives you've considered**
Only thing that can be done at this moment is separetly list out each attribute in it's own present function AND override each default error message.
**Express the feature either with a change to resource syntax, or with a change to the resource interface**
For example
```elixir
validates do
validate required([:field1, :field2, :field3, :field4])
end
```
Contributor guide
Assessment
This issue has not been assessed yet.