From 281d14d896d706fc54802ec15c00bb486b00edb7 Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Sat, 25 Mar 2023 22:13:36 +0100 Subject: [PATCH] Invoking "changed" when a Checkbox.SetChecked() is called. Resolves #825 --- checkbox.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/checkbox.go b/checkbox.go index a48a075..abab2b5 100644 --- a/checkbox.go +++ b/checkbox.go @@ -64,9 +64,15 @@ func NewCheckbox() *Checkbox { } } -// SetChecked sets the state of the checkbox. +// SetChecked sets the state of the checkbox. This also triggers the "changed" +// callback if the state changes with this call. func (c *Checkbox) SetChecked(checked bool) *Checkbox { - c.checked = checked + if c.checked != checked { + if c.changed != nil { + c.changed(checked) + } + c.checked = checked + } return c } @@ -148,8 +154,7 @@ func (c *Checkbox) SetDisabled(disabled bool) FormItem { } // SetChangedFunc sets a handler which is called when the checked state of this -// checkbox was changed by the user. The handler function receives the new -// state. +// checkbox was changed. The handler function receives the new state. func (c *Checkbox) SetChangedFunc(handler func(checked bool)) *Checkbox { c.changed = handler return c