Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
now we use populate method of the widget in the checkboxwidget as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyglazyrindev committed Nov 20, 2021
1 parent d851e8a commit 2d05ff5
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions core/form_widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,21 @@ func (w *CheckboxWidget) SetValue(v interface{}) {

func (w *CheckboxWidget) Render(formRenderContext *FormRenderContext, currentField *Field) template.HTML {
// spew.Dump("12", w.FieldDisplayName)
value := TransformValueForWidget(w.Value)
if value != "" && value != "false" {
w.Attrs["checked"] = "checked"
var value interface{}
if w.Populate != nil {
value = w.Populate(w, formRenderContext, currentField)
} else {
value = TransformValueForWidget(w.Value)
}
if valueS, ok := value.(string); ok {
if valueS != "" && valueS != "false" {
w.Attrs["checked"] = "checked"
}
}
if valueB, ok := value.(bool); ok {
if valueB {
w.Attrs["checked"] = "checked"
}
}
// w.Value = nil
data := w.Widget.GetDataForRendering(formRenderContext, currentField)
Expand All @@ -1072,6 +1084,9 @@ func (w *CheckboxWidget) Render(formRenderContext *FormRenderContext, currentFie
}

func (w *CheckboxWidget) ProceedForm(form *multipart.Form, afo IAdminFilterObjects, renderContext *FormRenderContext) error {
if w.Populate != nil {
w.Populate(w, renderContext, nil)
}
if w.ReadOnly {
return nil
}
Expand Down

0 comments on commit 2d05ff5

Please sign in to comment.