How to clear UDInput after submit?

The content of Inputfields persist after submitting.
Is there a function or method to clear what has been entered?

Show-UDModal -Height "100%" -Width "50%" -Header {
            #New-UDHeading -Size 4 -Text "New Department"
        } -Content { 
             New-UDInput -Title "Add Blue Collar Worker Entry" -Id "NewBCWorkerForm" -Content {
                New-UDInputField -Type textbox -Name 'FullName' -Placeholder 'Full Name' 
                New-UDInputField -Type textbox -Name 'EmployeeNumber' -Placeholder 'Employee Number'
                New-UDInputField -Type textbox -Name 'Title' -Placeholder 'Title'
                New-UDInputField -Type select -Name 'WorkingArea' -Placeholder 'Working Area' -Values @("BC Production","BC Construction")
               
            } -Endpoint {
                param($FullName, $EmployeeNumber, $Title, $WorkingArea)

                Show-UDToast -Message "$FullName, $EmployeeNumber, $Title, $WorkingArea" -Duration 6000

                

                Hide-UDModal

            } -SubmitText "Create"
        }

Try: New-UDInputAction -ClearInput

Put that at the end of your Endpint for New-UDinput. I think it should probably just do this by default but it’s just kinda been like that for along time.

That’s almost too simple. -Toast is mandatory though, but close enough :smiley:

Thanks

Lol weird. Ok. I will take a look at it.

Adam,

Have you had a chance to look at this? I need to clear inputs on several New-UDInputFields? I am using New-UDInputAction and a content block that goes through a couple of try/catch blocks that have Show-UDToast within. I can’t use New-UDInputAction -ClearInput -Toast “some message” because the toast is limited compared to what you can do with Show-UDToast.

Thanks!!
Guy

Hi @guy ok it’s in no shape or way a proper fix, but it will force the user to refresh the page, and will clear the results…which is using the custom component I made UniversalDashboard.UDSweetAlert its on powershell gallery and market place. I see you are using a toast, so where you got ShowUDToast change that to something like:-

New-UDInputAction -Content {New-UDSweetAlert -type success -title "Thank you $FullName" -text "You submitted the data correctly. Please press F5 after closing this message"} 

As for some reason this causes the inputs to disappear…so this is a bug I need to look into but the bug may help you achieve what you want…? Peace

Thanks for the suggestion @psDevUK! I do love the way the UDSweetAlerts look but I would hate to rely on a bug that I’m sure your going to squash at some point. I’m hoping this is just something simple, and @adam can include a fix when he has time. In the meantime, I may try and see if I can use New-UDElement and Sync-UDElement to clear the inputs on my own. Thanks again @psDevUK for your input!

I added a PR to make this so you don’t have to Toast.

You’ll be able to just: New-UDInputAction -ClearInput

1 Like

Awesome! Thank you, Adam.

I tried -ClearInput but it did not clearup the New-UDInputField -Type textbox.

clear
Get-UDDashboard | Stop-UDDashboard

$Dashboard = New-UDDashboard -Title “New-UDGridLayout” -Content {

$filename = $null
$sloption = $null
$ServerNames = $null
$BrowseFile = $null

New-UDInput -Title "Server List Option" -Id "ServerList" -Content {
    New-UDInputField -Type textbox -Name "ServerNames" -DefaultValue $null
} -Endpoint {
    param($ServerNames)
    
    New-UDInputAction -ClearInput -Content {
        $ServerNames = $null
        Set-UDElement -Id "ServerList" -Attributes @{ 
                                type = "textbox"
                                value = $null;
                                }
        Sync-UDElement -Id "ServerList" 
    }

}

}
Start-UDDashboard -Dashboard $Dashboard -Port 10001 #-AdminMode

Try with 2 New-UDInputAction, one for content and one to clearinput

1 Like

Hi Bo,

Can you please post a sample code using 2 New-UDInputAction.
You can revise the code I posted.

I tried your suggestion but it did not work for me.
I might be doing it wrong.

Thanks.