Form validation with checkbox not working

Product: PowerShell Universal
Version: 1.5.15

I am having an issue with the formvalidation on a checkbox not working in a dashboard.

New-UDCheckBox -Id "cb_Move" -Label "Ok To Move" -disabled

I enable it with a different control, which works correctly

The form validation looks like this

elseif(($eventdata.cb_Move).checked -ne "true"){
        New-UDFormValidationResult -ValidationError "You must Check the OK box to start the move"
    }

I have tried doing ($eventdata.cb_Move).checked -eq "false" and ($eventdata.cb_Move).checked -ne "$true" and neither of them seem to clear the form validation. The form keeps the error on the page and will not allow submission. I have also tried leaving it enabled, that does not make a difference.

You will just want to check the cb_Move for $true or $false.

    New-UDForm -Content {
        New-UDCheckBox -Id "cb_Move" -Label "Ok To Move" 
    } -OnValidate {
        if($eventdata.cb_Move -eq $false) {
            New-UDFormValidationResult -ValidationError "You must Check the OK box to start the move"
        }
        else 
        {
            New-UDFormValidationResult -Valid
        }
    } -OnSubmit {

    }

Tried that, it didn’t work either.

elseif(($eventdata.cb_move).checked -eq "$false"){
    New-UDFormValidationResult -ValidationError "You must Check the OK box to start the move"
}

It allows submission even if the box is not checked

I didn’t use the boolean variable since the value returned from the check box seems to be a string. I have another dashboard where the checkbox uses string, and it works.

elseif(($eventdata.cb_Empnum).checked -eq "true" -and $eventdata.tb_EmpID -eq $null){
    New-UDFormValidationResult -ValidationError "You must enter an Employee ID"
}

In that dashboard if cb_Empnum is checked and tb_EmpID is empty it throws the error. If cb_Empnum is not checked I don’t get the error.

You need to remove the “.checked” part.

elseif($eventdata.cb_move -eq $false){
    New-UDFormValidationResult -ValidationError "You must Check the OK box to start the move"
}

That did it. I wonder how my other dashboard works then. I’ll poke around.

Thanks!

1 Like