Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilhelm Murdoch committed Mar 19, 2014
1 parent e32b863 commit c2054e4
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions README.md
Expand Up @@ -164,41 +164,31 @@ If this form generated errors, you'd get the following output:
]
```

If you want to return a JSON representation of your form, you can do the following:
If you want only a list of fields that failed validation and their associated error messages, you can use do:

```python
>>> print form.form()
>>> print results.errors()
{
'username': 'wilhelm',
'password': 'root',
'password-confirm': 'root',
'email': 'wilhelm@gmail.com'
'username': [
'heh.',
'lolwut?',
'It is either too long or too short, man.'
]
}
```

You can also override a rule's default error message by specifiying your own:

```python
results = collection.Collection().append([
field.Field('field_name', 'foo').append([
IsEmail(error='Dude, seriously?')
])
]).run()
```

If you want quick access to any fields in your collection that contain errors:
If you want to return a JSON representation of your form, you can do the following:

```python
>>> print results.errors()
>>> print form.form()
{
'field_name': [
'Dude, seriously?'
]
'username': 'wilhelm',
'password': 'root',
'password-confirm': 'root',
'email': 'wilhelm@gmail.com'
}
```

These convenience methods become quite handy when you're using this library for JSON API error responses.

## Extending

Writing your own rules is quite simple. You just have to make sure your own rules derive from class `validator.rule.Rule`.
Expand Down

0 comments on commit c2054e4

Please sign in to comment.