I’m trying to only show a Toast notification if someone switches the switch off, but that variable seems to be empty no matter what.
Code:
New-UDStep -OnLoad {
New-UDTextbox -Id ‘IDNumber’ -Label ‘ID Number’
New-UDSwitch -Checked $true -OnChange { Show-UDToast -Message “Testing – Event Data: --> $EventData <—” -Duration 30000}
} -Label “Step 1”
Behavior:
Am I doing this incorrectly? Thanks in advance!
In v3, I just grab $Body, which is True or False.
New-UDSwitch -OnChange {
$session:switchValue = $Body
Show-UDToast -Message "switch is: $session:switchvalue"
Sync-UDElement -Id 'randomOuter'
}
Cheers,
Steve.
TmJr75
August 30, 2020, 7:48pm
3
I experience the same in 1.3.1 after the upgrade on Dashboard version 2.9.
Something must have changed during this upgrade / functionallity changed ?
@adam is this a bug?
adam
August 31, 2020, 4:52pm
4
Hmmm. Yeah. This should be in the upgrade docs but I think I’m also going to fix this so that you don’t actually have to change this. It should continue to set $EventData.
1 Like
L-P-G
April 22, 2021, 9:59pm
6
@adam just FYI, this is also an issue on NewUDTable running on Universal v1.5.15
adam
April 22, 2021, 10:01pm
7
Thanks for the heads up. I’ve opened an issue to track this because I did not remember about this: New-UDSwitch $EventData not working · Issue #142 · ironmansoftware/issues · GitHub
adam
April 23, 2021, 6:50pm
8
@L-P-G Can you provide a script for this bug? I’m trying this and it’s working as expected.
$Data = @(
@{Dessert = 'Frozen yoghurt'; Calories = 1; Fat = 6.0; Carbs = 24; Protein = 4.0}
@{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
@{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
@{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 4.0}
@{Dessert = 'Gingerbread'; Calories = 200; Fat = 6.0; Carbs = 24; Protein = 4.0}
)
$Columns = @(
New-UDTableColumn -Property Dessert -Title Dessert -Render {
New-UDSwitch -OnChange { Show-UDToast "EventData: $EVentData"}
}
New-UDTableColumn -Property Calories -Title Calories
New-UDTableColumn -Property Fat -Title Fat
New-UDTableColumn -Property Carbs -Title Carbs
New-UDTableColumn -Property Protein -Title Protein
)
New-UDTable -Data $Data -Columns $Columns -Sort -Export
L-P-G
April 25, 2021, 5:34pm
9
@adam , Sure, see below:
New-UDDynamic -Id 'table' -Content {
$Data = Get-Content C:\PSU\Tables\Status.hash | ConvertFrom-Json
$Columns = @(
New-UDTableColumn -Property Table -Title "Table" -ShowSort -IncludeInExport -IncludeInSearch
New-UDTableColumn -Property Customer -Title "Customer" -ShowSort -IncludeInExport -IncludeInSearch
)
New-UDTable -Data $Data -Columns $Columns -ShowSelection -Dense -OnRowSelection {
$Element = Get-UDElement -Id 'Customer'
$EventData = $Body | ConvertFrom-Json | ConvertFrom-Json
($Data | Where-Object { $_.Table -eq $EventData.Table }).Customer = $Element.Value
$Data | ConvertTo-Json | Out-File C:\PSU\Tables\Status.hash -Force
Sync-UDElement -Id 'table'
}
} -LoadingComponent {
"Loading"
}
adam
April 26, 2021, 2:27pm
10
You shouldn’t need to create $EventData yourself here.
New-UDTable -Data $Data -Columns $Columns -ShowSelection -Dense -OnRowSelection {
$Element = Get-UDElement -Id 'Customer'
# Skip this: $EventData = $Body | ConvertFrom-Json | ConvertFrom-Json
($Data | Where-Object { $_.Table -eq $EventData.Table }).Customer = $Element.Value
$Data | ConvertTo-Json | Out-File C:\PSU\Tables\Status.hash -Force
Sync-UDElement -Id 'table'
}
For example, I just tried this on 1.5.16 and it works as expected.
$Data = try { get-service -ea Stop | select Name,@{n = "Status";e={ $_.Status.ToString()}},@{n = "StartupType";e={ $_.StartupType.ToString()}},@{n = "StartType";e={ $_.StartType.ToString()}} } catch {}
$Columns = @(
New-UDTableColumn -Property Name -Title "Service Name" -ShowSort -IncludeInExport -IncludeInSearch -ShowFilter -FilterType text
New-UDTableColumn -Property Status -Title Status -ShowSort -DefaultSortColumn -IncludeInExport -IncludeInSearch -ShowFilter -FilterType select
New-UDTableColumn -Property StartupType -Title StartupType -IncludeInExport -ShowFilter -FilterType select
New-UDTableColumn -Property StartType -Title StartType -IncludeInExport -ShowFilter -FilterType select
)
New-UDTable -Id 'service_table' -Data $Data -Columns $Columns -Title 'Services' -ShowSearch -ShowPagination -ShowSelection -Dense -OnRowSelection {
$Item = $EventData
Show-UDToast -Message "$($Item | out-string)"
}
New-UDButton -Text "GET Rows" -OnClick {
$value = Get-UDElement -Id "service_table"
Show-UDToast -Message "$( $value.selectedRows | Out-String )"
}
L-P-G
April 26, 2021, 8:45pm
11
Weird, I just commented out the $EventData defining line and the debugger showed it populated correctly. I wonder if I changed something or if I wasn’t running on enough coffee? I guess feel free to disregard my post then.
Thanks for the quick turn around