martini-contrib / binding

Martini handler for mapping and validating a raw request into a structure.
MIT License
140 stars 45 forks source link

If a form field is bool, and it's submit value is false, then it will fail to validate #28

Closed guotie closed 10 years ago

guotie commented 10 years ago

If a form field is bool, and it's submit value is false, then it will fail to validate "required"

mholt commented 10 years ago

Yup. The same goes for int fields that can be 0 and strings that can be empty, etc. Fields that can have their type's zero-value as a valid value should not be marked as required.

Unfortunately I don't know a convenient way to work around that. I'm open to suggestions!

guotie commented 10 years ago

just check if the form has this field

mholt commented 10 years ago

That may work for form deserialization, but is inconsistent with JSON. I don't want to write our own JSON parser...

guotie commented 10 years ago

so, just fix form first.

guotie commented 10 years ago

And i think this should be noticed in the document

mholt commented 10 years ago

At this point I feel it best to keep the behavior across Json and Form deserialization consistent. You're welcome to fork the package and modify it if it will suit your needs better.

And this is documented: look here in the README under 'Validate'.

mholt commented 10 years ago

@guotie I just thought, you might be able to use a pointer to your bool: *bool and I think it will deserialize as a null pointer if it doesn't exist in the request. That might get you what you want.