From a3b6e7d7842628f8315c717b32c3c4beaac6f869 Mon Sep 17 00:00:00 2001 From: Michael Kudenko Date: Sat, 19 Mar 2022 18:58:34 +1300 Subject: [PATCH] Add README example for building error messages --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 2b7bfae..c18bb1f 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,21 @@ validate('presence', 'foo', { presence: true }); validate('length', 'foo', { min: 1 }); ``` +### Messages +When validation fails, you can build the error message manually. + +```js +import messages from 'ember-validators/messages'; +import validateLength from 'ember-validators/length'; + +const options = { min: 5 }; +const result = validateLength('foo', options); + +const errorMessage = messages.getMessageFor(result.type, { ...options, description: 'Page title' }); + +alert(errorMessage); // "Page title is too short (minimum is 5 characters)" +``` + ## Validator Method Signature Each validator has the following signature: