Ash FrameworkAF
Ash Framework3y ago
18 replies
gordoneliel

How to: Conditional validation with built-ins

Im trying to validate an embedded field "payment_method" when a certain param/attribute has a specific value. I've tried to do this:

      accept [:collection_method, :billing_cycle_anchor, :customer, :payment_method]
      validate present([:collection_method, :customer])
      validate present(:payment_method),
        where: [argument_equals(:collection_method, :charge_automatically)],
        message: "payment_method is required when collection method is charge_automatically"


But when I omit the "payment_method" param when sending a request to create, I get a "Invalid value provided for payment_method: is invalid." I've tried argument_equals, attribute_equals and none seem to work
Was this page helpful?