validate method

  1. @override
Result validate(
  1. dynamic value, {
  2. bool exists = true,
})
override

Main validation method. Use this method if you want to validate that a dynamic value is valid, and get an error message if not.

You can also call isValid if you just want to check if the value is valid.

If you want to to throw an error use validateOrThrow

exists If set to true, the value is consider to "exist", this is most useful for optional fields in maps.

Will throw an error if used with async validators

Implementation

@override
Result validate(dynamic value, {bool exists = true}) {
  // This validator must be used within an `eskema` map validator
  // to have access to the parent map.
  return Result.invalid(
    value,
    expectations: [
      Expectation(
        message: '`when` validator can only be used inside an `eskema` map validator',
        value: value,
      )
    ],
  );
}