Skip to main content

Required If

Check if the input value is not empty if another input has a specific value.

The validation rule does not require a value to run.

Example

src/app/orders/controllers/checkout.ts
// ...
createPost.validation = {
rules: {
creditCardNumber: ["requiredIf:paymentMethod,creditCard"],
},
};

In this case, the creditCardNumber input will be required if the paymentMethod input has a value of creditCard.

It can also receive an array of values:

src/app/orders/controllers/checkout.ts
// ...
createPost.validation = {
rules: {
creditCardNumber: ["requiredIf:paymentMethod,creditCard,debitCard"],
},
};