From b443ed5723e6d1750f01a3286291244b5cb15903 Mon Sep 17 00:00:00 2001 From: Thijs Louisse Date: Thu, 25 Nov 2021 15:23:07 +0100 Subject: [PATCH] chore(form-core): add a better example for custom validator --- docs/docs/systems/form/validate.md | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/docs/systems/form/validate.md b/docs/docs/systems/form/validate.md index a37b0e590..19bade65d 100644 --- a/docs/docs/systems/form/validate.md +++ b/docs/docs/systems/form/validate.md @@ -113,27 +113,25 @@ As you can see the 'validators' property expects a map (an array of arrays). So, All validators extend from the default `Validator` class. Below example is an example of a validator could look like: ```js -class MyValidator extends Validator { +class EqualsText extends Validator { + static validatorName = 'EqualsText'; + + /** + * Returns true when 'activated' (c.q. in error/warning/info state) + * @param {string} modelValue + */ execute(modelValue, param) { - const hasFeedback = false; - if (modelValue === param) { - hasFeedback = true; - } - return hasFeedback; + return modelValue !== param; } - static get validatorName() { - return 'Required'; - } - - static getMessage({ fieldName }) { - return `Please fill in ${fieldName}`; + static getMessage({ fieldName, modelValue, formControl }) { + return `Please make sure values are equal`; } } ``` ```html - + ``` ## Installation