Checkbox can enable other components, but not disable

Product: PowerShell Universal
Version: 5.6.9

I have a checkbox set to enable or disable other components. The checkbox will enable the select and textbox, but it won’t disable them.

Made an app with just those components to makes sure it wasn’t something else interfering and I get the same result. I do get the UDToasts so I know the If statement is working, it’s just the Set-UDElement that isn’t working.

New-UDApp -Content {
    New-UDCheckBox -id "Checkbox" -Label "Checkbox" -OnChange {
        if ($true -eq $body){
            show-udtoast -message $body
            set-udelement -id "select" -properties @{disabled = $false}
            set-udelement -id "textbox" -properties @{disabled = $false}
        }
        Elseif ($false -eq $body) {
            show-udtoast -message $body
            set-udelement -id "select" -properties @{disabled = $true}
            set-udelement -id "textbox" -properties @{disabled = $true}
        }
    }
    New-UDHtml -Markup "<br>"
    new-udselect -id "select" -label "Select" -option {
            new-udselectoption -name "name" -value "name"
    } -OnChange {
        show-udtoast -message $EventData[0] -Duration 5000
    } -disabled
    New-UDHtml -Markup "<br>"
    New-UDTextbox -id "textbox" -label "textbox" -disabled
}

I also tried setting the disabled switch to a variable, updating that, and putting those components into a dynamic, but that gives me the same result. Checking the box will enable, but unchecking with not disable the components.

New-UDApp -Content {
    $session:SelectDisabled = $true
    $session:TextDisabled = $true
    New-UDCheckBox -id "Checkbox" -Label "Checkbox" -OnChange {
        if ($true -eq $body){
            show-udtoast -message $body
            $session:SelectDisabled = $false
            $session:TextDisabled = $false
            sync-udelement "dynamic"
        }
        Elseif ($false -eq $body) {
            show-udtoast -message $body
            $session:SelectDisabled = $true
            $session:TextDisabled = $true
            sync-udelement "dynamic"
        }
    }
    New-UDHtml -Markup "<br>"
    new-uddynamic -id "dynamic" -Content {
        new-udselect -id "select" -label "Select" -option {
                new-udselectoption -name "name" -value "name"
        } -disabled:$session:SelectDisabled
        New-UDHtml -Markup "<br>"
        New-UDTextbox -id "textbox" -label "textbox" -disabled:$session:TextDisabled
    }
}

Hi, I dont know if the problem comes from the “elseif” or the condition “$false -eq $body” but it works if you use a switch

New-UDCheckBox -id "Checkbox" -Label "Checkbox" -OnChange {
    switch($Body) {
        $true {
            set-udelement -id "select" -properties @{disabled = $false}
            set-udelement -id "textbox" -properties @{disabled = $false}
        }
        $false {
            set-udelement -id "select" -properties @{disabled = $true}
            set-udelement -id "textbox" -properties @{disabled = $true}

        }
    }
}

New-UDHtml -Markup "<br>"
new-udselect -id "select" -label "Select" -option {
        new-udselectoption -name "name" -value "name"

} -OnChange {
    show-udtoast -message $EventData[0] -Duration 5000

} -disabled
New-UDHtml -Markup "<br>"
New-UDTextbox -id "textbox" -label "textbox" -disabled
1 Like

Yep, that did it. Super weird. I would get the toast for the ElseIf, but the Set-UDElement didn’t work.

Working either way though. Thanks!

yep the problem was with if ($true -eq $body) statement

this code works:

New-UDApp -Content {
    New-UDCheckBox -Id "Checkbox" -Label "Checkbox" -OnChange {
        if ($body -eq $true ) {
            Show-UDToast -Message $body
            Set-UDElement -Id "select" -Properties @{disabled = $false }
            Set-UDElement -Id "textbox" -Properties @{disabled = $false }
        }
        Else {
            Show-UDToast -Message $body
            Set-UDElement -Id "select" -Properties @{disabled = $true }
            Set-UDElement -Id "textbox" -Properties @{disabled = $true }
        }
    }
    New-UDHtml -Markup "<br>"
    New-UDSelect -Id "select" -Label "Select" -Option {
        New-UDSelectOption -Name "name" -Value "name"
    } -OnChange {
        Show-UDToast -Message $EventData[0] -Duration 5000
    } -Disabled
    New-UDHtml -Markup "<br>"
    New-UDTextbox -Id "textbox" -Label "textbox" -Disabled
}

Hmm. I’ve always read that when doing things like $null or a boolean comparison you should have the $null/$true/$false because powershell does hard type comparisons so I’ve always done that on the left side.