Skip to content

Commit

Permalink
Update CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
jfairbank committed Jan 4, 2017
1 parent 3ee65e4 commit 4a052ce
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
## v1.1.0

### More customization with `createValidator`

* Credit: [@Zagitta](https://github.com/Zagitta).

Sometimes you may want to customize what your custom validator function takes as
a field label and what it returns for an error. Revalidate has always allowed
you to return something besides a string error message when validation fails.
For example, you can also return an object. This is especially useful for
internationalization with a library like
[react-intl](https://github.com/yahoo/react-intl). In addition to returning an
object, you can now also pass in an object for your field label. To do this
you'll need to pass in an object to your curried validation function with a
`field` property. The `field` property can then be an object (or another data
type). What you define `field` to be will be what is passed into your message
creator function. Here is a contrived example:

```js
const isRequired = createValidator(
error => value => {
if (value == null || value === '') {
return error;
}
},

// Instead of a string, config is the i18n config we
// pass in to the curried validation function.
config => config
);

const requiredName = isRequired({
id: 'name',
defaultMessage: 'Name is required',
});

requiredName('Jeremy');
// undefined

requiredName();
// { id: 'name', defaultMessage: 'Name is required' }
```

---

## v1.0.0

### :tada: First major release - NO breaking changes
Expand Down

0 comments on commit 4a052ce

Please sign in to comment.