Conditional demo

Checkout

Conditional billing validation plus required shipping and payment method choices.

Back to demo gallery
Payment method

Developer notes

The billing field is only required when another control makes that rule relevant.

Conditional field

<input id="billing-toggle" name="useBilling" type="checkbox" />

<input
  id="billing-address"
  name="billingAddress"
  data-validate="billing-address"
/>

Registered rule

validator.registerRule("billingAddress", ({ form, value }) => {
  const enabled = form.querySelector("#billing-toggle").checked;
  return {
    valid: !enabled || String(value).trim() !== "",
    messageKey: "required"
  };
});