Custom validation example
It would be very helpful to have an example validation in the docs for custom validations. I am getting hung up creating an error that implements the form error protocol. The following generates an error but is then stripped out before rending the form.
error = Ash.Error.to_ash_error("Domain or company is required")
6 Replies
So when given a string, we create an
UnknownError
which won't show in a form (for security reasons)
If you do it like this:
then it will create an Ash.Error.Invalid
and that will show up in the form
you can use fields
instead of field
if you want to target multiple fieldsThanks
@Zach Daniel Given the above how do I return the modified changeset from the validate function? {:error, changeset} throws an error because it does not have a path. The docs indicate {:error, Ash.error()} which does not appear to accept a changeset?
correct, you can't return a changeset
if you want to return a new changeset, you need to use a
change
instead
why do you want to return a new changeset, out of curiosity?The example you provided above produces a new changeset. I just want the validation to produce an error in the form.
oh, sorry
š
{:error, field: :field_name, message: "Message"}
Thanks so much. That worked.