Textbox enable/disable does not work within a stepper

Textbox enable/disable does not work within a stepper

avatar

The text box does not get enabled or disabled when we select/unselect the checkbox. Instead, it keeps the initial value (disabled=$true). The same code works fine if not run within a stepper.

            New-UDStepper -Steps {

                # Step 1

                New-UDStep -OnLoad {

                    New-UDElement -tag 'div' -Content { "Move on" }

                } -Label "Step 1 - Go ahead"


                # Step 2

                New-UDStep -DisablePrevious -OnLoad {

                    New-UDStack -Spacing 2 -FullWidth -AlignItems 'baseline' -Content {

                        New-UDCheckBox -Id 'CheckBoxRadio' -Label 'Click to enable or disable radio buttons and text box' -Checked:$false -Disabled:$false -OnChange {

                            $disableRadio = (Get-UDElement -Id 'CheckBoxRadio').Checked -eq $false

                           

                            Set-UDElement -Id 'RadioGroup1' -Properties @{ 'disabled' = $disableRadio }

                            Set-UDElement -Id 'StartTime' -Properties @{ 'disabled' = $disableRadio }

                        }

       

                        New-UDRadioGroup -Id 'RadioGroup1' -Content {

                            New-UDRadio -Label 'Option 1' -Value 'Option 1'

                            New-UDRadio -Label 'Option 2' -Value 'Option 2'

                        } -Value "Option 1" -Disabled:$true

       

                        New-UDTextbox -Id 'StartTime' -Label 'Start time:' -Value '08:00' -Disabled:$true -MaximumLength 5 -type "text" -OnValidate {

                            $elementValue = (Get-UDElement -Id 'StartTime').Value

                            if ($elementValue -notmatch '^([0-1][0-9]|2[0-3]):[0-5][0-9]$')

                            {

                                New-UDValidationResult -ValidationError "Please enter the time correctly (00:00-23:59)"

                            }

                            else

                            {

                                New-UDValidationResult -Valid ""

                            }

                        }

                    }

       

                } -Label "Step 2 - Check if the elements get enabled and disabled"

All Comments (1)

avatar

Hello ilazovic,

Thank you for the clear example, it made this easy to test. I ran your code word for word on PowerShell Universal 2026.3.4 and got the same result. Inside the stepper the radio buttons follow the checkbox, but the text box stays disabled. The same controls outside a stepper work. The server does send the change to the text box, so your script is correct and the text box on the page is what ignores it. Sending the value along with the change does not help, and your -OnValidate block is not the cause. I am passing this to our development team and will let you know what comes of it.

Until then, the version of your step 2 below worked on the same server. It puts the text box in a New-UDDynamic and redraws it from the checkbox with Sync-UDElement, the way our page on dynamic regions shows (https://docs.devolutions.net/powershell-universal/apps/components/utilities/dynamic-regions). It saves what the user typed first, because the redraw would otherwise put the text box back to 08:00. Your validation message still shows, a time typed before disabling and enabling again is kept, and the stepper's -OnFinish receives it. The two session variables are reset each time step 2 loads, so the step starts disabled again on a new pass.

New-UDStep -DisablePrevious -OnLoad {

$Session:StartTimeDisabled = $true

$Session:StartTimeValue = '08:00'

New-UDStack -Spacing 2 -FullWidth -AlignItems 'baseline' -Content {

New-UDCheckBox -Id 'CheckBoxRadio' -Label 'Click to enable or disable radio buttons and text box' -Checked:$false -Disabled:$false -OnChange {

$disableRadio = (Get-UDElement -Id 'CheckBoxRadio').Checked -eq $false

Set-UDElement -Id 'RadioGroup1' -Properties @{ 'disabled' = $disableRadio }

$Session:StartTimeValue = (Get-UDElement -Id 'StartTime').Value

$Session:StartTimeDisabled = $disableRadio

Sync-UDElement -Id 'StartTimeArea'

}

New-UDRadioGroup -Id 'RadioGroup1' -Content {

New-UDRadio -Label 'Option 1' -Value 'Option 1'

New-UDRadio -Label 'Option 2' -Value 'Option 2'

} -Value "Option 1" -Disabled:$true

New-UDDynamic -Id 'StartTimeArea' -Content {

New-UDTextbox -Id 'StartTime' -Label 'Start time:' -Value $Session:StartTimeValue -Disabled:$Session:StartTimeDisabled -MaximumLength 5 -type "text" -OnValidate {

$elementValue = (Get-UDElement -Id 'StartTime').Value

if ($elementValue -notmatch '^([0-1][0-9]|2[0-3]):[0-5][0-9]$')

{

New-UDValidationResult -ValidationError "Please enter the time correctly (00:00-23:59)"

}

else

{

New-UDValidationResult -Valid ""

}

}

}

}

} -Label "Step 2 - Check if the elements get enabled and disabled"

Let me know how it goes in your app.

Best regards,

Michel

Michel Audi