Is there a dedicated function like with Hide-UDModal or something or something I can do with Set-UDElement? I can’t find anything in the documentation apart from the New-UDProgress cmdlet.
I want to show a UDProgress while I’m waiting for the result of a REST submission then remove it when the response is received.
Tried Remove-UDElement, but that didn’t seem to do it.
(v3)
Oh, I guess I can put it in a UDModal and then just hide that. Not ideal, but it’ll work.
Edit: Err, well this doesn’t work like I thought it would.
New-UDButton -Text "Click Me" -OnClick {
Show-UDModal -Content {
New-UDProgress -circular -color Blue
Sleep 5
Hide-UDModal
}
}
I expected this to show a UDModal with a Progress spinner then hide it after 5 seonds. It actually waited for 5 seconds and then showed the UDModal?
What haven’t I understood?
Got it. This works:
$cache:showprogress = $true
New-UDDynamic -id 'sync-progress' -Content{
If($cache:showprogress){
New-UDProgress -id 'progress' -circular
}
}
New-UDButton -Text "Finish Him" -onclick {
$cache:showprogress = $false
Sync-UDElement -id 'sync-progress'
}
Figured it might help some others
Oh and while I was fiddling working this out, I got to this first - same idea, but updating the percentcomplete and then making it disappear when you hit 100.
$cache:progress = 5
New-UDDynamic -id 'sync-progress' -Content{
If($cache:progress -lt 100){
New-UDProgress -id 'progress' -percentcomplete $cache:progress
}
}
New-UDButton -Text "Half Way" -onclick {
$cache:progress = 50
Sync-UDElement -id 'sync-progress'
}
New-UDButton -Text "Finish Him" -onclick {
$cache:progress = 100
Sync-UDElement -id 'sync-progress'
}
2 Likes
raymix
September 28, 2020, 10:35pm
4
Here’s another example that works as a visual preloader using modal while your script gathers data
New-UDButton -Text 'Load data' -OnClick {
Show-UDModal -Content {
New-UDProgress
} -FullWidth
# Simulate 3 seconds of loading data
Start-Sleep -Seconds 3
Hide-UDModal
# Do stuff here, like open another modal or Sync-UDElement to reload your content
Show-UDModal -Content {
New-UDTypography -Text "Finished loading data"
} -FullWidth
}
2 Likes