Switch not working in OnChange event

So I must be having a bad day. The Switch in the below code only ever triggers the default selection despite the fact that the default selection throw up a Toast showing that the $Body type is a string and has a value that matches on of the other options!

    New-UDRadioGroup -Id 'rdFilter' -Label "Filter Type" -Content {
        New-UDRow -Columns {
            New-UDColumn -LargeSize 3  -Content {
                New-UDRadio -Label "PowerShell Expression Language" -Value 'PSELFILTER'
            }
            New-UDColumn -LargeSize 3 -Content {
                New-UDRadio -Label "LDAP" -Value 'LDAPFILTER'
            }
        }
    } -OnChange {

        $Radio = $Body

        switch ($Radio)
        {
            ('PSELFILTER') {
                Set-UDElement -Id 'txtFilter' -Properties @{'helperText' = "$pselfilter" }
            }

            ('LDAPFILTER') {
                Set-UDElement -Id 'txtFilter' -Properties @{'helperText' = "$ldapfilter" }
            }

            Default {
                Show-UDToast -Message "$($Body.GetType()) $Body" -Duration 3000
                Set-UDElement -Id 'txtFilter' -Properties @{'helperText' = "$ldapfilter" }
            }
        }
    }-Value 'PSELFILTER'
Product: PowerShell Universal
Version: 3.2.8

You should add a break to the end of each switch statement, otherwise they keep evaluating IIRC

I thought that was only when there could be multiple matches though? in this case the matches are unique.

1 Like

It looks like quotes are being included. Try this:

        $Radio = $Body.Trim('"')

Yeah that was it! Thanks!!

1 Like