Skip to content

Commit

Permalink
Invoking "changed" when a Checkbox.SetChecked() is called. Resolves r…
Browse files Browse the repository at this point in the history
  • Loading branch information
rivo committed Mar 25, 2023
1 parent 87723e5 commit 281d14d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions checkbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 281d14d

Please sign in to comment.