Set-UDElement without triggering onValidate?

Product: PowerShell Universal
Version: 4.4.0

I have a form, that contains

  • Subject - textField
  • Description - textArea
  • Email - textField
  • 5 dropdown selectionboxes.

When the onValidate is triggered, it checks if the fields contain the correct data - if not, the Icon property is set (to a red arrow) - thus marking the field that contains invalid data.

However - when triggering the Set-UDElement, another onValidate is triggered - thus starting an endless loop of onValidate events. Causing browser to spike in CPU usage.

I would suggest using a dummy element outside of the form’s inputs, and using the validation failure hook to replace the content with the icon.

If you are using the New-UDGrid cmdlets for layout on the form, it should be pretty easy to adjust the column structure to allow room for, say, a New-UDElement -Tag "div" -Id "subjectIcon", which can then be edited in the following ways:

  1. Adding the icon on validation failure:
Add-UDElement -ParentId "subjectIcon" -Content { New-UDIcon <# ... #> }
  1. Removing the icon on validation success:
# For your use case this is likely unnecessarily verbose.
# You can use other means, but the general structure here is
# hopefully helpful.
$elementChildren = (Get-UDElement -Id "subjectIcon").Content
foreach ($child in $ElementChildren ) {
  Remove-UDElement -Id $child.Id
}

Please let me know if this works; since you aren’t editing properties of input types, this shouldn’t trigger onValidate, but I may be wrong. This is all theoretical at this point.
:wavy_dash:ZG

1 Like

Could you please share the code for this? I am stuck with handling form validation properly.