UDCheckbox questions

Can’t seem to find an easy answer but I am looking for how I would setup a Checkbox that when unchecked it runs a command and when it is checked it runs a command.

I have it populate a txt file with some data when its checked but I want to have it clear that data when I uncheck the box.

This is accomplished via the -OnChange handler and the $EventData variable. The below should accomplish what you’re looking for:

New-UDCheckbox -Label 'My Test CheckBox' -OnChange {
    if($EventData) {
        # If the CheckBox is checked, Do this Stuff
    } else {
        # If the CheckBox is unchecked, do this stuff
    }
}

Good luck!

1 Like

Man one day I am going to be like you. I couldn’t find that anywhere. Thank you so much for taking the time out to help. Its greatly appreciated!!!

1 Like

I know this question has been answered, but I only just seen it. So just wanted to chip in, that on the ‘new’ default dashboard on the nightly builds, Adam has been kind enough to provide a load of examples with code of UI controls so for your question there is an example:-

New-UDCheckbox -Label “Checkbox” -OnChange {
Show-UDToast -Message $EventData
}
Releases · ironmansoftware/universal-dashboard · GitHub