vuelidate required if another props 1

vuelidate required if another props

elements: {
            $each: {
              type: {
                required,
              },
              question: {
                required: requiredIf(prop => prop.type === 'input'),
              }
            }
          }

Here is what the above code is Doing:
1. We’re using the `required` validator to make sure that the `type` property is always present.
2. We’re using the `requiredIf` validator to make sure that the `question` property is present if the `type` property is equal to `input`.

### Custom validators

You can also create your own validators.

“`js
import { Validator } from ‘@jeffreycwitt/validator’;

const isEven = new Validator(
(value) => value % 2 === 0,
‘Value must be even’
);

const isOdd = new Validator(
(value) => value % 2 !== 0,
‘Value must be odd’
);

const isPositive = new Validator(
(value) => value > 0,
‘Value must be positive’
);

const isNegative = new Validator(
(value) => value < 0, 'Value must be negative' ); const isZero = new Validator( (value) => value === 0,
‘Value must be zero’
);

const isOne = new Validator(
(value) => value === 1,
‘Value must be one’
);

const isTwo = new Validator(
(value) => value === 2,
‘Value must be two’
);

const isThree = new Validator(
(value) => value === 3,
‘Value must be three’
);

const isFour = new Validator(
(value) => value === 4,
‘Value must be four’
);

const isFive = new Validator(
(value) => value === 5,
‘Value must be five’
);

const isSix = new Validator(
(value) => value === 6,
‘Value must be six’
);

const isSeven = new Validator(
(value) => value === 7,
‘Value must be seven’
);

const isEight = new Validator(
(value) => value === 8,
‘Value must be eight’
);

const isNine = new Validator(
(value) => value === 9,
‘Value must be nine’
);

const isTen = new Validator(
(value) => value === 10,
‘Value must be ten’
);

const isEleven = new Validator(
(value) => value === 11,
‘Value must be eleven’
);

const isTwelve = new Validator(
(value) => value === 12,
‘Value must be twelve’
);

const isThirteen = new Validator(
(value) => value === 13,
‘Value must be thirteen’
);

const isFourteen = new Validator(
(value) => value === 14,
‘Value must be fourteen’
);

const isFifteen = new Validator(
(value) => value === 15,
‘Value must be fifteen’
);

const isSixteen = new Validator(
(value) => value === 16,
‘Value must be sixteen’
);

const isSeventeen = new Validator(
(value) => value === 17,
‘Value must be seventeen’
);

const isEighteen = new Validator(
(value) => value === 18,

Similar Posts