Skip to content

Commit 9f5262f

Browse files
committed
explain how to get message for errors; closes #335
1 parent 0f39079 commit 9f5262f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ A simple, reactive schema validation package for Meteor. It's used by the [Colle
4646
- [Custom Validation](#custom-validation)
4747
- [Manually Adding a Validation Error](#manually-adding-a-validation-error)
4848
- [Asynchronous Custom Validation on the Client](#asynchronous-custom-validation-on-the-client)
49+
- [Getting a List of Invalid Keys and Validation Error Messages](#getting-a-list-of-invalid-keys-and-validation-error-messages)
4950
- [Other Validation Context Methods](#other-validation-context-methods)
5051
- [Other SimpleSchema Methods](#other-simpleschema-methods)
5152
- [Customizing Validation Messages](#customizing-validation-messages)
@@ -714,7 +715,7 @@ This doesn't change the fact that validation is synchronous. If you use this wit
714715

715716
You can use a technique similar to this to work around asynchronicity issues in both client and server code.
716717

717-
### Other Validation Context Methods
718+
### Getting a List of Invalid Keys and Validation Error Messages
718719

719720
Call `myContext.invalidKeys()` to get the full array of invalid key data. Each object
720721
in the array has two keys:
@@ -724,6 +725,19 @@ at [Manually Adding a Validation Error](#manually-adding-a-validation-error).
724725

725726
This is a reactive method.
726727

728+
There is no `message` property. Once you see what keys are invalid, you can call `ctxt.keyErrorMessage(key)` to get a reactive message string.
729+
730+
If you want to add a `message` property to the invalidKeys array objects (which would no longer be reactive), you can do
731+
732+
```js
733+
var ik = ctxt.invalidKeys();
734+
ik = _.map(ik, function (o) {
735+
return _.extend({message: ctxt.keyErrorMessage(o.name)}, o);
736+
});
737+
```
738+
739+
### Other Validation Context Methods
740+
727741
`myContext.keyIsInvalid(key)` returns true if the specified key is currently
728742
invalid, or false if it is valid. This is a reactive method.
729743

0 commit comments

Comments
 (0)