pombreda / formalchemy

Automatically exported from code.google.com/p/formalchemy
MIT License
0 stars 0 forks source link

Binding to form data with missing form elements gives a KeyError #152

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
*What steps will reproduce the problem?

import formalchemy
class Bob(object):
  username = formalchemy.Field(type=formalchemy.fatypes.Text)

fs = formalchemy.FieldSet(Bob)
fs = fs.bind(Bob, data={'notusername':'asdf'})
fs.validate()

*What is the expected output? What do you see instead?
Validation to return False, with the errors dict showing which items are 
missing.

*Please use labels and text to provide additional information.
I modified 1.3.2 to, instead of throwing a KeyError, validate but give a 
ValidationError on the items that didn't have a coresponding data key.  Form 
items can also be given an .optional() argument to say that it is ok to not 
include the form item in the data, and what the default value will be.  If 
.optional() is not given then no value given (except for checkbox/radio values) 
will not validate.

If you find this functionality useful I can update the docs to reflect these 
changes as well.

If the patch is in the wrong format, please let me know.

Original issue reported on code.google.com by warrench...@gmail.com on 21 Oct 2010 at 8:59

Attachments:

GoogleCodeExporter commented 9 years ago
Oops, wrong diff, use this one

Original comment by warrench...@gmail.com on 21 Oct 2010 at 9:00

Attachments: