Closed guotie closed 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!
just check if the form has this field
That may work for form deserialization, but is inconsistent with JSON. I don't want to write our own JSON parser...
so, just fix form first.
And i think this should be noticed in the document
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'.
@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.
If a form field is bool, and it's submit value is false, then it will fail to validate "required"