From c2054e4a719f333f4c42f0303d56a691a6e28149 Mon Sep 17 00:00:00 2001 From: Wilhelm Murdoch Date: Thu, 20 Mar 2014 00:56:00 +1100 Subject: [PATCH] updated readme --- README.md | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 8eb9c7d..1744dfa 100644 --- a/README.md +++ b/README.md @@ -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`.