Conditional field
<input id="billing-toggle" name="useBilling" type="checkbox" />
<input
id="billing-address"
name="billingAddress"
data-validate="billing-address"
/>
Conditional demo
Conditional billing validation plus required shipping and payment method choices.
Back to demo galleryThe billing field is only required when another control makes that rule relevant.
<input id="billing-toggle" name="useBilling" type="checkbox" />
<input
id="billing-address"
name="billingAddress"
data-validate="billing-address"
/>
validator.registerRule("billingAddress", ({ form, value }) => {
const enabled = form.querySelector("#billing-toggle").checked;
return {
valid: !enabled || String(value).trim() !== "",
messageKey: "required"
};
});