Add in required validation, replicating Ecto's validate_required functionality
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
validates do
validate required([:field1, :field2, :field3, :field4])
end
Looks like a good plan to me :) I won't be able to do this in the near future, so PRs welcome!
@zachdaniel feel free to assign to me if you'd like. I'll probably get to this pretty quickly