|
|
@@ -44,8 +44,10 @@ func (f *FormField) AddValidator(validator ValidatorFunc) *FormField {
|
|
|
}
|
|
|
|
|
|
/* SetValidators configures validators list in form field */
|
|
|
-func (f *FormField) SetValidators(validators ValidatorsList) *FormField {
|
|
|
- f.Validators = validators
|
|
|
+func (f *FormField) SetValidators(validators ...ValidatorFunc) *FormField {
|
|
|
+ for _, validator := range validators {
|
|
|
+ f.AddValidator(validator)
|
|
|
+ }
|
|
|
return f
|
|
|
}
|
|
|
|
|
|
@@ -129,18 +131,18 @@ func (f *FormField) Float() float64 {
|
|
|
return 0.0
|
|
|
}
|
|
|
|
|
|
-/* GetBool returns boolean value for checkbox fields */
|
|
|
+/* GetBool returns true if checkbox is selected, always returns nil error */
|
|
|
func (f *FormField) GetBool() (bool, error) {
|
|
|
- /* placeholder */
|
|
|
- return false, nil
|
|
|
+ /* if box is checked, it sends a non-empty value */
|
|
|
+ return len(f.Value) != 0, nil
|
|
|
}
|
|
|
|
|
|
-/* GetChecked returns true if checkbox has been checked and its value is "on" */
|
|
|
-func (f *FormField) GetChecked() bool {
|
|
|
- return f.Value == "on"
|
|
|
+/* Bool returns true if checkbox is selected, ignores errors */
|
|
|
+func (f *FormField) Bool() bool {
|
|
|
+ return len(f.Value) != 0
|
|
|
}
|
|
|
|
|
|
-/* formFieldTemplate is a template to render FormField element in HTML format */
|
|
|
+/* fieldsTemplateStr is a template to render FormField element in HTML format */
|
|
|
//go:embed fields.html
|
|
|
var fieldsTemplateStr string
|
|
|
|