camper/pkg/form/checkbox.go

30 lines
524 B
Go

/*
* SPDX-FileCopyrightText: 2023 jordi fita mas <jfita@peritasoft.com>
* SPDX-License-Identifier: AGPL-3.0-only
*/
package form
import (
"database/sql/driver"
"net/http"
)
type Checkbox struct {
Name string
Checked bool
Error error
}
func (checkbox *Checkbox) setError(err error) {
checkbox.Error = err
}
func (checkbox *Checkbox) FillValue(r *http.Request) {
checkbox.Checked = len(r.Form[checkbox.Name]) > 0
}
func (checkbox *Checkbox) Value() (driver.Value, error) {
return checkbox.Checked, nil
}