-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
BoolField.validate currently contains the following code:
// If POSTing from a `checkbox` style input, the key's absence means `false`.
let bool = value.bool ?? false
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:
// If POSTing from a `checkbox` style input, the key's absence means `false`.
let bool = value.string != nil
or check both, as a failsafe:
// If POSTing from a `checkbox` style input, the key's absence means `false`.
let bool = value.string != nil || (value.bool ?? false)
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:
let shouldResetPassword = data["shouldResetPassword"]?.string != nil
let sendEmail = data["sendEmail"]?.string != nil
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels