Product: PowerShell Universal
Version: 1.5.8
Hi All
I have two lists, a list of possible options and a list of selected options. I want to present the list of possible options with the selected options overlaid/preselected. I want the user to be able to select/deselect various options and then I want to take the result and save it to a database.
Initially I attempted to use a Checkbox method, this I can get the Selected options to show up but can’t work out how to save them to list to use later, whenever I select a checkbox the last value in the list is duplicated, ie
New-UDDashboard -Title "Hello, World!" -Content {
$EventPossibleOptions = [System.Collections.ArrayList]@('Logon','Logoff','Forward','Disable','Push')
$EventPossibleOptionsSelected = [System.Collections.ArrayList]@('Disable','Push')
$Session:EventTestSelections = $EventPossibleOptionsSelected
Foreach ($PossibleValue in $EventPossibleOptions) {
if ($PossibleValue -in $EventPossibleOptionsSelected) {$Checked = $true} ELSE {$Checked = $false}
New-UDCheckBox -id 'ArrayCheckBox' -Label "$($PossibleValue)" -Checked $Checked -OnChange {
Show-UDToast -Message "Setting to $Body" -Duration 1200 -MessageSize 30 -Position topCenter -Theme 'dark'
if ($body -eq 'True'){
$Session:EventTestSelections.Add("$PossibleValue")
} ELSE {
$Session:EventTestSelections.Remove("$PossibleValue")
}
}
}
New-UDButton -Text 'Get Value' -OnClick {
Show-UDToast -Message "$($Session:EventTestSelections)"
}
}
I then tried using a UDSelect, this presents nicer but I can’t seem to select more then 1 default option, so i don’t think it’s compatible, ie
New-UDDashboard -Title "Hello, World!" -Content {
$EventPossibleOptions = [System.Collections.ArrayList]@('Logon','Logoff','Forward','Disable','Push')
$EventPossibleOptionsSelected = [System.Collections.ArrayList]@('Disable','Push')
$Session:EventTestSelections = $EventPossibleOptionsSelected
New-UDSelect -Option {
Foreach ($PossibleValue in $EventPossibleOptions){
New-UDSelectOption -Name "$PossibleValue" -Value $PossibleValue
}
} -Multiple -DefaultValue $EventPossibleOptionsSelected -OnChange {
Show-UDToast -Message $Body
$Session:EventTestSelections = $Body
}
New-UDButton -Text 'Get Value deducted' -OnClick {
Show-UDToast -Message "$($Session:EventTestSelections)"
}
}
You can see the values being added, but the default values are treated as a string rather then selecting them.
How would people here go about achieving the outcome I desire?
Thanks
MaCCa