Stepper Component usage

Product: PowerShell Universal
Version: 2.6.2

So using the below code I select a file then enter some text then finish. The final page shows the $Body json fine but $Body.context and $Body.currentStep are empty?? What am I doing wrong??

New-UDDashboard -Title "Hello, World!" -Content {
    New-UDStepper -Steps {
        New-UDStep -OnLoad {
            New-UDElement -tag 'div' -Content { "Select a csv format file containing users to lookup in AD." }
            New-UDUpload -Id 'userFile' -Text 'Browse' -Accept '.csv' -OnUpload {
                $Session:CSV = Import-CSV $Body.FileName
            }
        } -Label "Select File"
        New-UDStep -OnLoad {
            New-UDElement -tag 'div' -Content { "Step 2" }
            New-UDElement -tag 'div' -Content { "Previous data: $Body" }
            New-UDTextbox -Id 'txtStep2' -Value $EventData.Context.txtStep2
        } -Label "Step 2"
    } -OnValidateStep {
        $Context = $EventData
        if ($Context.CurrentStep -eq 0 -and $Context.Context.userFile -eq $null )
        {
            New-UDValidationResult -ValidationError "No file specified."
        }
        else
        {
            New-UDValidationResult -Valid 
        }
    } -OnFinish {
        New-UDElement -Tag 'div' -Id 'result' -Content {$Body}
        New-UDElement -Tag 'div' -Id 'context' -Content {$Body.context}
        New-UDElement -Tag 'div' -Id 'step' -Content {$Body.currentStep}
    } -Orientation 'vertical'
}

$Body is the raw JSON string so it won’t have properties. We automatically convert $Body to a PSCustomObject ($EventData) in all event handlers. In your OnSubmit, use $EventData.

       New-UDElement -Tag 'div' -Id 'result' -Content {$Body} # Body is JSON string
        New-UDElement -Tag 'div' -Id 'context' -Content {$EventData.context} # EventData is PSCustomObject
        New-UDElement -Tag 'div' -Id 'step' -Content {$EventData.currentStep}

This still appears to be empty?

OK so not sure what was going on but it seems to be working as expected now.

1 Like