New-UDChip -OnDelete get chip element label

Product: PowerShell Universal
Version: 1.5.18

Hi all,

I’m trying to get the label of a chip when it is deleted, but the $Element variable below is just blank. The $EventData variable is valid and shows the GUID Id of the chip.

New-UDChip -Label $chipUserName -Avatar $chipUser.avatar -AvatarType image -OnDelete {
    Show-UDToast -Message "eventdata is: $($EventData)"
    $Element = Get-UDElement -Id $EventData
    Show-UDToast -Message "element is: $($Element)"
    Show-UDToast -Message "element.value is: $($Element.Value)"

Does anyone have any ideas? Or even better, a way to hold another value behind the chip label (I’d like to have the label of the chip as the username and the value to be the user’s SID).

What I’m trying to do is list the members of an AD group, each as their own chip with the user’s avatar. This works fine. Then on delete of the chip I want to remove that user from ther AD group using Remove-ADGroupMember


I’ve worked out something that is working for me, wrapping all the udchips in an element then getting the content of that element where the id = the selected chip’s id…

New-UDElement -Tag 'div' -Id 'chipsForUsers' -Content {
    foreach($user in $usersInADgroup) {
        $udUser = Get-UDuserInfo $user.SID
            if ($udUser) {
                if ($null -eq $udUser.SamAccountName { 
                    $chipUserName = $user.SamAccountName
                } else {
                    $chipUserName = $udUser.SamAccountName
                New-UDChip -Style @{'font-weight'='800'} -Label $chipUserName -Avatar $udUser.avatar -AvatarType image -OnDelete {
                Show-UDToast -Message "eventdata is: $($EventData)"
                $Element = Get-UDElement -Id 'chipsForUsers'
                Show-UDToast -Message "clicked chip data: $(($Element.Content) | where{$ -eq $EventData})" -Duration 8000
                $usersSamAccountNameToRemove = (($Element.Content) | where{$ -eq $EventData}).label
1 Like