Skip to content

Commit 09a3595

Browse files
authored
Merge pull request #62 from jelhan/patch-1
Update README to showcase ember-cp-validations
2 parents 4a23726 + 0487354 commit 09a3595

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,29 @@ ember install ember-cp-validations
3535
Usage
3636
------------------------------------------------------------------------------
3737

38-
Define your model and its validations as described in [Ember CP Validations](https://github.com/offirgolan/ember-cp-validations).
38+
Define your model and its validations as described in [Ember CP Validations](https://github.com/offirgolan/ember-cp-validations):
39+
40+
```js
41+
import Ember from 'ember';
42+
import { validator, buildValidations } from 'ember-cp-validations';
43+
44+
const Validations = buildValidations({
45+
username: validator('presence', true),
46+
email: validator('format', { type: 'email' }),
47+
password: validator('length', { min: 10 }),
48+
});
49+
50+
export default Ember.Component.extend(Validations, {
51+
username: null,
52+
email: null,
53+
password: null,
54+
});
55+
```
56+
3957
Then assign the model to your form:
4058

4159
```hbs
42-
<BsForm @model={{changeset this.user this.userValidations}} as |form|>
60+
<BsForm @model={{this}} as |form|>
4361
<form.element @label="Username" @controlType="text" @property="username" />
4462
<form.element @label="Email" @controlType="email" @property="email" />
4563
<form.element @label="Password" @controlType="password" @property="password" />

0 commit comments

Comments
 (0)