How to get checked item value

Hi,
I have the below code

New-UDDynamic -Id “Application_Server_Names” -Content {

New-UDExpansionPanelGroup -Children {

  New-UDExpansionPanel  -Title "Application Servers" -Children  {

      New-UDList  -Children {


          foreach ($Server in $Cache:ServerNames) {

              New-UDElement  -Tag 'div' -Content { 

                  $Icon = New-UDIcon -Icon "server" -Size sm -Regular -Style @{color = '#0d1421' }

                  $CheckedIcon = New-UDIcon -Icon  "server" -Size sm 

                  New-UDCheckBox -id "Application_servers_$($Server)" -Icon $Icon -CheckedIcon $CheckedIcon -Style @{color = '#2196f3' } -Label "$($Server)"  -LabelPlacement end -OnChange {

                      Show-UDToast -Message $EventData -Duration 600

                  }

              }  

                                  

          }

      }

                      

  }

}

}

$CacheServerNames - contains a list of server names. i would like to get the checked item values. I have seen all the examples only seems to show how to get the checked item with the attributes property. not sure what i am missing . reading some old posts i found that i can display $eventData to find what are the properties but this ends up blank. using the latest version of powershell universal

any help would be much appreciated

TIA

We’re fixing the issue with missing $EventData in 1.4 but until then you can use the $Body variable.

 New-UDCheckBox -id "Application_servers_$($Server)" -Icon $Icon -CheckedIcon $CheckedIcon -Style @{color = '#2196f3' } -Label "$($Server)"  -LabelPlacement end -OnChange {

                      Show-UDToast -Message $Body-Duration 600

                  }
1 Like

Thanks heaps Adam will give that a whirl !

Note that the $Body variable is a JSON string so you might have to use ConvertTo-Json to get what you really need out of it.

thanks for that. thats strange within the -OnChange block the $body returns just True or False nothing else.

That is the current value of the check box or at least it should be.

yep. that works for me. So to grab the value in checkbox will declare a $CheckBoxApplicationSelectionArray = @{} and check if body is true i will add and if false i will remove it from the array.

thanks again for your help

1 Like