-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BoolField.validate is broken #15
Comments
This also leads to a follow-up problem with
The problem is that unchecked checkboxes do not transmit a value at all, so this would cause an unchecked checkbox to never show up in
If the checkbox is unchecked, this will always fall back to So I would suggest to add a special case in
/cc @bygri |
I'm not the maintainer of this package; I'm not sure anyone is. This was built for an early version of Vapor where I explicitly added support for this. In the browsers I tested, the value of a checked input was always |
Thanks for the info! I might prepare a PR then. FYI, checkboxes by default do not transmit "on" or "off", but nothing if they are unchecked and their value attribute if checked, see e.g. https://stackoverflow.com/questions/4260918/why-do-html-checkboxes-only-transmit-an-on-value. |
Incorrect, on Safari and Firefox at least, a |
My bad, sorry, I missed that. Thanks for the clarification! |
BoolField.validate
currently contains the following code:However, if a checkbox named e.g. "someBoolValue" has been checked, its form value will be a string with content "someBoolValue". Thus, you should be checking for the field's string value instead:
or check both, as a failsafe:
See e.g. https://github.com/nodes-vapor/admin-panel-provider/blob/master/Sources/AdminPanelProvider/Models/AdminPanelUserForm.swift (lines 62/63 at the moment) for examples of where this is done correctly:
The text was updated successfully, but these errors were encountered: