New-UDStepper -OnPrevious (?)

Product: PowerShell Universal
Version: 5.4.3

@adam ,

Is there a way to hook into a user pressing the “Back” button on a stepper to, say, remove some of the context data?

Not at the moment. We actually don’t have a great way to update the context of the stepper from within the step or validation events. It’s just trying to glean what it can from the form controls. It’s a bit of an issue because it causes stuff like this.

I was able to manage this behavior with a matching session variable.

I am running conditional logic to add an element if a particular condition is true within the validation step of the stepper. That conditional logic checks for either the context value being null or the session variable being null. That element has an additional onChange handler that sets the value of the session variable to the value of the context, then within the OnLoad block of the step itself I clear that session variable.

I’m not sure this can be easily refactored into a bug fix/enhancement, since it relies on the session data, but it IS possible for future readers. A light example:

New-UDStepper -Steps {
  New-UDStep -OnLoad {
    $Session:testVariable = $null
    New-UDCheckbox -Label "Test the validation" -Id "activateValidation"
  }
} -OnValidateStep {
  if ($EventData.activateValidation) -and ($null -eq $EventData.validationTest -or $null -eq $Session:testVariable)) { 
    New-UDValidationResult -ValidationError "Validate the form by typing in the box"
    # OnValidate for text boxes, onChange for select etc. just make sure it fires minimally
    Add-UDElement -ParentId "parent" -Content {
      New-UDTextbox -Label "Enter anything here" -Id "validationTest" -OnValidate { $Session:testVariable = $EventData }
    }
  }
}

Disclaimer that the above has not been tested to be working, just an example of how the flow would work.

1 Like