delta
March 7, 2023, 1:57pm
1
Product: PowerShell Universal
Version: 1.4.6
Does a way exist to dynamically hide and show an entire layout? But I have yet to find a working way to hide/show an entire UD-GridLayout based on the input from a selectoption.
I know it’s possible to hide/show specific elements using the -OnChange flag on a UD-SelectOption
adam
March 7, 2023, 8:46pm
2
Not directly but you can do something like this. Set a session variable and then reload the dynamic region to rerun the logic about which item is selected.
New-UDSelect -OnChange {
$Session:SelectedOption = $EventData
Sync-UDElement -Id 'region'
}
New-UDDynamic -Id 'region' -Content {
if ($Session:SelectedOption -eq 'gridlayout1')
{
New-UDGridLayout #...
}
}
delta
March 8, 2023, 3:24pm
3
I’m struggling to get that to work; maybe you can see what’s wrong. I have several selects in this page but here’s the one that matters
$TopLayout = '{"lg":[
{"w":2,"h":2,"x":0,"y":4,"i":"grid-element-ServerTypeSelect","moved":false,"static":false}
]}'
New-UDGridLayout -Content {
New-UDSelect -Id "ServerTypeSelect" -Label "Server Type" -DefaultValue "Windows" -Option {
New-UDSelectOption -Name "Windows Server" -Value "Windows"
New-UDSelectOption -Name "Linux" -Value "Linux"
New-UDSelectOption -Name "Appliance" -Value "Appliance"
} -OnChange {
$Session:SelectOption = $EventData
Write-Host $Session:SelectOption
Sync-UDElement -Id 'dynOSSelect'
Sync-UDElement -Id 'dynDisk'
Sync-UDElement -Id 'dynAdmin'
}
} -Layout $TopLayout
New-UDDynamic -Id 'dynAdmin' -Content {
if ($Session.SelectedOption -eq "Windows") {
New-UDGridLayout -Id "AdminInputLayout" -Content {
#Windows
New-UDTextbox -Label "Local Administrators" -Id "LocalWindowsAdmins" -Placeholder "Per IT Security, use SA Accounts only" -Disabled
} -Layout $WindowsSuperUserLayout
}
elseif ($Session.SelectedOption -eq "Linux") {
#Linux
New-UDGridLayout -Id "AdminInputLayout" -Content {
New-UDTextbox -Label "SSH Access" -Id "LocalLinuxAdmins" -Placeholder "Per IT Security, use SA Accounts only" -Disabled
New-UDSelect -Label "Sudoers Access" -Id "SudoersSelect" -DefaultValue "Select as many Sudo Groups as Needed" -Disabled -Option {
$aLinuxSudoersGroups = Get-ADGroup -Filter 'gidNumber -like "*"' -Properties gidNumber | Select-Object SamAccountName, gidNumber | Sort-Object SamAccountName
foreach ($group in $aLinuxSudoersGroups) {
if (!($group.gidNumber -eq '450') -and !($group.gidNumber -eq '10019')) {
New-UDSelectOption -Name $group.SamAccountName -Value $group.SamAccountName
}
}
} -Multiple: $true
} -Layout $LinuxSuperUserLayout
}
else {
New-UDGridLayout -Id "AdminInputLayout" -Content {
}
}
}