How can I do conditional validation for OR logic, where we check to see if 1 of the 2 values is present or both values are present.
So, for example, if I want to check to make sure that the email
or the mobile
fields are filled... I want to be able to pass a list into fields
of validate_required_inclusion
to validate that at least 1 of the fields in the list is not null.
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:email, :first_name, :last_name, :password_hash, :role, :birthdate, :address1, :address2, :city, :state, :zip, :status, :mobile, :card, :sms_code, :status])
|> validate_required_inclusion([:email , :mobile])
end
def validate_required_inclusion(changeset, fields, options \\ []) do
end
How can I do this conditional OR validation?
present?
logic may differ. For example, the current implementation would consider an empty list as present. – Comprador