requiredUnless rule (v3)
Require a field unless another field already has a value.
Usage
bootstrapValidate('#input', 'requiredUnless:#secondaryEmail:Enter at least one email address')Options
| Name | Description | Example |
|---|---|---|
otherInput | string: Selector for the field that can satisfy the requirement. | #secondaryEmail |
Live Example
Checking...
Source
/** * @since 2.3.0 * @example #secondaryEmail * @error Enter at least one email address * @param otherInput string: Selector for the field that can satisfy the requirement. * @description Require a field unless another field already has a value. */export default function requiredUnless(input: RuleInput, otherInput: RuleOption) { const resolvedInput = document.querySelector(String(otherInput)) as RuleInput | null; return Boolean(input.value.length || resolvedInput?.value.length);}