Hello,
I have a stepper where the first choise decides if the second step is skipped or not. The second step has a validation where a checkbox needs to be checked to go further. But if I choose to skip the second step the stepper gives an error that the form is invalid like in the picture, I think that it is because of the validation of the checkbox.
Now my question is if there is a way to disable that stepper error?
Thank you in advance!
Product: PowerShell Universal Dashboard
Version: 3.8.12
Can you please post your code, or a reproducer that shows the issue? This will help us narrow down the root cause.
$Pages += New-UDPage -Name 'Test' -Content {
New-UDStepper -Steps {
New-UDStep -OnLoad {
New-UDSelect -Id "Employee" -Label "Skip step 2?" {
New-UDSelectOption -Name "Yes" -Value "Yes"
New-UDSelectOption -Name "No" -Value "No"
}
} -Label "Choose if step will be skipped"
New-UDStep -OnLoad {
New-UDSelect -Id "Required" -Label "This is required." {
New-UDSelectOption -Name "Hello" -Value "Hello"
}
} -Label "Step 2"
New-UDStep -OnLoad {
New-UDElement -tag 'div' -Content { "Step 3" }
} -Label "Step 3"
} -Orientation vertical -OnFinish {
New-UDTypography -Text 'Nice! You did it!' -Variant h3
} -OnValidateStep {
$Choise = $Body | ConvertFrom-Json
switch ($Choise.CurrentStep){
0 {
if ([string]::IsNullOrWhiteSpace($Choise.Context.Employee)){
New-UDValidationResult -ValidationError 'Select an option please!'
}else {
if ($Choise.Context.Employee -eq "Yes") {
New-UDValidationResult -ActiveStep 2
}elseif ($Choise.Context.Employee -eq "No") {
New-UDValidationResult -ActiveStep 1
}
}
}
1 {
if ([string]::IsNullOrWhiteSpace($Choise.Context.Required)){
New-UDValidationResult -ValidationError 'Select an option please!'
}else {
New-UDValidationResult -Valid
}
}
2{
New-UDValidationResult -Valid
}
}
}
}
New-UDDashboard -Title 'TestDashboard' -Pages $Pages
So this code gives always an “Form invalid” error when you go to next steps and I don’t get why.
The only issue I see is in your step-skipping section. Adding the -Valid param on the New-UDValidationResult calls makes it work for me. As shown in the docs, it would be something like this:
New-UDValidationResult -Valid -ActiveStep 2