Set-UDElement - disable option not working on checkbox

Hello,

I’m trying to disable the checkbox when I click on the button but it’s not working. Not sure if i’m using the good way to do that or if it’s a bug. I’m using the bellow code.

Thanks for your help.

      New-UDCheckbox -Id "checkbox" -Label "checkbox"

      New-UDButton -Text "Disable" -OnClick {
         Set-UDElement -Id "checkbox" -Attributes @{disabled = $true}                              
      }

Hey ClissonFlorian
If you use get-udelement -id “checkbox” in the console, you’ll be able to see all the properties of that element, in the attributes i’m only seeing checked, not disabled, so in your example, checking and unchecking would work but not disabling, for that I’ve used similar methods to the below before:

if($null -eq $session:checkboxsplat){
    $session:checkboxsplat = @{
        disabled = $false
    }
}

new-udelement -tag div -id "checkbox_container" -endpoint {
    New-UDCheckbox -Id "checkbox" -Label "checkbox" @session:checkboxsplat
}

New-UDButton -Text "Disable" -OnClick {
    $session:checkboxsplat = @{
        disabled = $true
    }
    sync-udelement -Id "checkbox_container"                 
}

New-UDButton -Text "Enable" -OnClick {
    $session:checkboxsplat = @{
        disabled = $false
    }
    sync-udelement -Id "checkbox_container"                 
}

The code above is in the context of an -endpoint page.
Basically, You can set either a session or cache variable for the disabled attribute, as its default if not already set (hence the $null).
Next, we splat that value into the -disabled parameter on the checkbox itself.
The button will then update the session or cache variable to the new value and actually sync the endpoint/container that I’m wrapping around the checkbox so that our parameter passes the latest value, if you do this directly on the checkbox it wont work.

By the way, if you want this to be just to the visiting user, use $session, if you want this to apply to all users, use $cache, but then put -broadcast on your sync-udelement command :+1:

:slight_smile: