New-UDInput Validate Issue


Got an issue with Validating my Inputs. As you can see from the image I have only filled out one field, but I can still hit Submit and it will run as if it was filled out.

Is it me missing something or a bug?

The code behind

$PageHome = New-UDPage -Name "MyPage" -Content {
New-UDLayout -Columns 2 -Content {
                New-UDInput -Title "MyInputs" -Content {
                    New-UDInputField -Type textbox -Name EmailAddress
                    New-UDInputField -Type textbox -Name SomeOtherField
                } -Endpoint {
                } -Validate

$Pages = @()
$Pages += $PageHome

$MyDashboard = New-UDDashboard -Title "Hello, World" -Pages $Pages

Get-UDDashboard | Stop-UDDashboard

Start-UDDashboard -Port 9001 -Dashboard $MyDashboard


Check out: Form Validation
You need to add validation rules to the params to check against.



Here is an example, so you can get started. So you do not really need New-UDInputField, each parameter from your param definition will be used as UDInputField (textbox).

New-UDInput -Title "Input Form" -Validate -SubmitText "Create User" -Id "selfservice_input_form_validate" -Endpoint {
              [Parameter(Mandatory, HelpMessage = "First name")]
              [Parameter(Mandatory, HelpMessage = "Last name")]
              [Parameter(Mandatory, HelpMessage = "Username (sAMAccountName")]
              [Parameter(Mandatory, HelpMessage = "Hostname (max. 15 characters)")]
              [UniversalDashboard.ValidationErrorMessage("The hostname you entered is invalid because it contains illegal characters (only lowercase, letters, numbers and dashes - 1-15 characters)")]
              [ValidateLength(1, 15)]
              [UniversalDashboard.ValidationErrorMessage("The ip address you entered is invalid.")]
              [Parameter(Mandatory, HelpMessage = "IP address" )]
              [ValidateScript( { $_ -is [ipaddress] })]
              [Parameter(Mandatory = $false, HelpMessage = "Homepage for this user")]
              [Parameter(Mandatory, HelpMessage = "Email address")]
              [UniversalDashboard.ValidationErrorMessage("The email address you entered is invalid.")]
              [Parameter(Mandatory, HelpMessage = "6 digit Employee ID")]
              [ValidateLength(6, 6)]
              [UniversalDashboard.ValidationErrorMessage("The employee id you entered is invalid.")]

Edit: Here is an example of the result
(reminder for me: I need to do a better css config for my input form… (this is only an internal example))

Hey Mordecai and thank you for the tip.

My issue is still that if I fill out everything except ‘First Name’(Didn’t clicked the textbox), I can still ‘Create User’ and ‘First Name’ is never validated and the script will continue to run.

(UDToast shows $FirstName)