Skip to content

Commit 437bdab

Browse files
committed
Expanded and fixed issues with the section about validation messages in documentation. Fixes #194
1 parent 2c20e40 commit 437bdab

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

docs/index.md

+26-9
Original file line numberDiff line numberDiff line change
@@ -350,22 +350,39 @@ If you supply a `validationMessage` property in the form definition, and if its
350350
string that will be used instead on any validation error.
351351
352352
If you need more fine grained control you can supply an object instead with keys matching the error
353-
codes of [tv4](https://github.com/geraintluff/tv4). See `tv4.errorCodes`
353+
codes of [tv4](https://github.com/geraintluff/tv4). tv4 is available
354+
globally in angular schema form along with it's error codes, they can be found in `tv4.errorCodes`.
354355
355356
Ex.
356357
```javascript
357-
{
358-
key: "address.street",
359-
validationMessage: {
360-
tv4.errorCodes.STRING_LENGTH_SHORT: "Address is too short, man.",
361-
"default": "Just write a proper address, will you?" //Special catch all error message
358+
var form = [
359+
"address.zip",
360+
{
361+
key: "address.street",
362+
validationMessage: {
363+
"default": "Just write a proper address, will you?"
364+
}
362365
}
363-
}
366+
];
367+
368+
form[1].validationMessage[tv4.errorCodes.STRING_LENGTH_SHORT] = "Address is too short, man.";
364369
```
365370
366-
You can also set a global `validationMessage` in *formDefaults* see
367-
[Global Options](#global-options).
371+
However, it can sometimes be clunky to use variables as keys so you can use the
372+
[error codes](https://github.com/geraintluff/tv4/blob/master/source/api.js#L1) directly.
373+
The example below also illustrates how to define validation messages globally. This uses
374+
*formDefaults*, for more info on how to use it, see [Global Options](#global-options).
368375
376+
```javascript
377+
scope.options = {
378+
formDefaults: {
379+
validationMessage: {
380+
200: "This string is too short, man.",
381+
302: "You can't just leave it blank, man."
382+
}
383+
}
384+
}
385+
```
369386
370387
### Inline feedback icons
371388
*input* and *textarea* based fields get inline status icons by default. A check

0 commit comments

Comments
 (0)