Product: PowerShell Universal
Version: 2.12.6
Problem
We have a stepper, that conditionally skips some steps as the user progresses.
When the user is going forwards through the form, this works exactly as expected. In the demo code below, the second question is skipped as expected when question 1 is set to yes. When the user is on question 3 and goes backwards, step 2 is skipped and goes back to question 1.
However, when the user progresses to question 4, and subsequently then goes backwards, question 2 is not skipped any more.
MVP Demo
New-UDStepper -Steps {
New-UDStep -Label 'Question 1' -OnLoad {
New-UDSelect -Id 'Q1' -DefaultValue $EventData.Context.Q1 -Option {
New-UDSelectOption -Name ' ' -Value ' '
@('Yes','No') | ForEach-Object {
New-UDSelectOption -Name $_ -Value $_
}
} -Label 'Skip Question 2?'
}
New-UDStep -Label 'Question 2' -OnLoad {
New-UDTextbox -Id 'Q2' -Label 'Q2' -Value $EventData.Context.Q2
}
New-UDStep -Label 'Question 3' -OnLoad {
New-UDTextbox -Id 'Q3' -Label 'Q3' -Value $EventData.Context.Q3
}
New-UDStep -Label 'Question 4' -OnLoad {
New-UDTextbox -Id 'Q4' -Label 'Q4' -Value $EventData.Context.Q4
}
} -OnValidateStep {
$Data = $Body | ConvertFrom-Json
switch ($Data.CurrentStep) {
0 {
if ([string]::IsNullOrWhiteSpace($Data.Context.Q1)) {
New-UDValidationResult -ValidationError 'Make a choice'
} elseif ($Data.Context.Q1 -eq 'Yes') {
New-UDValidationResult -Valid -ActiveStep 2
} else {
New-UDValidationResult -Valid
}
}
1 {
if ([string]::IsNullOrEmpty($Data.Context.Q2)) {
New-UDValidationResult -ValidationError 'Q2 cannot be blank'
} else {
New-UDValidationResult -Valid
}
}
2 {
if ([string]::IsNullOrEmpty($Data.Context.Q3)) {
New-UDValidationResult -ValidationError 'Q3 cannot be blank'
} else {
New-UDValidationResult -Valid
}
}
Default {
New-UDValidationResult -Valid
}
}
} -OnFinish {
New-UDElement -Tag 'pre' -Id 'result' -Content {
$Body | ConvertFrom-Json | Format-List | Out-String
}
} -Orientation vertical
Am I doing something incorrectly? Is this expected behaviour?
Thanks in advance!