OnValidate Multiple Fields

Hy,
I’m trying to validate a form with two fields. Starting off from your example in the documentation, I expanded it for the seconds field. But It is just working for the first on the second one is always in a failed state.

New-UDExpansionPanelGroup -Children {
New-UDExpansionPanel -Title 'Add Members to Group' -Icon 'user' -Children {
    New-UDForm -Id 'grouptoadd' -Content {
        New-UDTextbox -Label 'Group' -id "Group" -Placeholder 'groupname, e.g. role.wks.'
        New-UDTextbox -Label 'Member' -id "Member" -Placeholder 'member to add'
    } -OnValidate {
    
        if ($EventData.Group -eq $null -or $EventData.Group -eq '' )
        {
            New-UDFormValidationResult -ValidationError "Group is required"
        }
        elseif ((Get-ADUser -Filter { Name -eq $EventData.Group }) -or (Get-ADComputer -Filter { Name -eq $EventData.Group }) -or (Get-ADGroup -Filter { Name -eq $EventData.Group }))
        {
            $GroupValid = $true
        }

        if ($EventData.Member -eq $null -or $EventData.Member -eq '' )
        {
            New-UDFormValidationResult -ValidationError "Member is required"
        }
        elseif ((Get-ADUser -Filter { Name -eq $EventData.Member }) )
        {
            $MemberValid = $true
        }

        if ($GroupValid -and $MemberValid)
        {
            New-UDFormValidationResult -Valid
        }
        .
        .
        .

Any idea what I’m doing wrong?
Thanks
Faba

Is there any answer to it?
thanks
Faba

Hi @faba, I’ve tried to reproduce this but it seems to work fine for me. I did adjust the form slightly to not check AD directly.

    New-UDForm -Id 'grouptoadd' -Content {
        New-UDTextbox -Label 'Group' -id "Group" -Placeholder 'groupname, e.g. role.wks.'
        New-UDTextbox -Label 'Member' -id "Member" -Placeholder 'member to add'
    } -OnValidate {
    
        if ($EventData.Group -eq $null -or $EventData.Group -eq '' )
        {
            New-UDFormValidationResult -ValidationError "Group is required"
        }
        else
        {
            $GroupValid = $true
        }

        if ($EventData.Member -eq $null -or $EventData.Member -eq '' )
        {
            New-UDFormValidationResult -ValidationError "Member is required"
        }
        else
        {
            $MemberValid = $true
        }

        if ($GroupValid -and $MemberValid)
        {
            New-UDFormValidationResult -Valid
        }
    } -OnSubmit {}

As you can see, I see the error message when member isn’t entered.

image

Then when I enter member, the error is resolved.

image

I validated this on version 1.5.15.