How to Clear "New-UDForm" Fields On Submit

Product: PowerShell Universal
Version: 4.3.4

I’ve created a simple form with a few fields, but I haven’t figured a way to clear the fields of the Form after submitting. Here’s a sample of the code:

New-UDForm -Id 'MainForm' -Content {

    New-UDTypography -Text 'File Sharing Site Access Request Form' -FontWeight bolder -Variant 'title'
    New-UDTypography -Text 'This is a self-service site to request access to common File Sharing Sites.'
    New-UDAutocomplete -Label "Staff Requesting Access" -FullWidth -Multiple -Option $UserOptions -Id 'UABox'
    New-UDTextbox -Label 'Related Matter' -Mask "00000.0000" -Placeholder "00000.0000" -Id 'CMbox'
    New-UDTextbox -Label 'Business Reason' -Placeholder ' ' -Multiline -Rows 5 -FullWidth -Id 'BRBox' 
    New-UDAutocomplete -Label 'Choose File Sharing Site' -Id 'FSPick' -FullWidth -Option $WebGroupDisplay
    New-UDCheckBox -Label 'I affirm that I know and trust the sender/source of the data.' -LabelPlacement end -Id 'CkBxConsent'

} -OnSubmit {

    Show-UDModal -Persistent -Content {

        New-UDTypography "Please check and confirm submitted data below for accuracy:" -GutterBottom -FontWeight bolder
        New-UDTable -Data $EventData

    } -Footer {

        New-UDButton -Text "Confirm" -ShowLoading -OnClick { 

            Invoke-PSUScript -Name "Submit-FileShareAccessRequest.ps1" -SubmittedData $EventData -Wait
            Hide-UDModal
            Show-UDToast 'Success!' -MessageSize Large -MessageColor Green -Duration 8000
            Clear-UDElement -Id 'MainForm'

        }

        New-UDButton -Text "Edit" -OnClick { 
            Hide-UDModal
        }

    }
}

Clear-UDElement -Id 'MainForm' is not working as expected. I also tried nulling the $EventData fileds with no luck.

Any ideas?

Based on my understanding, Clear-UDElement removes all children from the parent (specified) component. So, its use case is different from what you are needing.

I would suggest using (Get-UDElement).Children[i].Value; like the following:

New-UDForm -Id "MainForm" -Content {
# ...
}  -OnSubmit {
            Show-UDModal -Persistent -Content {
                New-UDButton -Text "Confirm" -OnClick {
                    $Children = Get-UDElement -Id "MainForm" -Property Children
                    foreach ($Child in $Children) {
                        Set-UDElement -Id $Child.Id -Properties @{ Value = "" }
                    }
                    Hide-UDModal
                    #Add your UD toast here as well
                }
            }
    }

Hopefully that helps!

Appreciate it, that did it!

1 Like