When using OnValidate for form elements all of them are validated (as either pass or fail) while using the element, without changing focus to another element. However when selecting any node on a TreeView the OnValidate script does not work until moving focus to another element (i.e. not just clicking blank space).
So the OnValidate script works as intended, but does not seem to follow the same process as the other elements (textbox, dropdown, radio button, autocomplete). I have found that clicking into another element also isn’t enough for the OnValidate to fire, you need to also fill out that element.
This is the code I have for the treeview
New-UDDynamic -Id "VMWareFolderLocation" -Content {
if ($null -ne $page:SelectedSite) {
$siteFolders = $null
$siteFolders = $Folders | Where-Object { (($_.Path -split '\\')[0]) -match $page:SelectedSite } | Sort-Object Name
New-UDTypography -Text "VMWare Folder for site: $($page:SelectedSite)"
New-UDTreeView -Id "FolderTreeView-$($page:SelectedSite)" -Node {
$rootFolders = $siteFolders | Where-Object { $_.Path -match '^[^\\]+\\[^\\]+$' }
foreach ($singleFolder in $rootFolders) {
New-UDTreeNode -Name $singleFolder.Name -Id $singleFolder.Id
}
} -OnNodeClicked {
$selectedId = $EventData.Id
$childFolders = $siteFolders | Where-Object { $_.ParentId -eq $selectedId } | Sort-Object Name
foreach ($child in $childFolders) {
New-UDTreeNode -Name $child.Name -Id $child.Id
}
$page:chosenFolderPath = ((($siteFolders | Where-Object { $_.ID -eq $selectedId }).Path) -replace '^[^\\]+\\', '') -replace '\\', '/'
}
}
}
on the -OnValidate snippet for the above TreeView
-OnValidate {
if ($null -eq $page:chosenFolderPath -or $page:chosenFolderPath -eq '') {
New-UDFormValidationResult -ValidationError "VM Folder is required"
}
else {
New-UDFormValidationResult -Valid
}
}
Product: PowerShell Universal
Version: 5.5.4
TIA
_Fonz