Invoking "changed" when a Checkbox.SetChecked() is called. Resolves #825

This commit is contained in:
Oliver 2023-03-25 22:13:36 +01:00
parent 87723e5081
commit 281d14d896
1 changed files with 9 additions and 4 deletions

View File

@ -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 { 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 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 // 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 // checkbox was changed. The handler function receives the new state.
// state.
func (c *Checkbox) SetChangedFunc(handler func(checked bool)) *Checkbox { func (c *Checkbox) SetChangedFunc(handler func(checked bool)) *Checkbox {
c.changed = handler c.changed = handler
return c return c