From de8090a6619e1467efe37f9678fc76cb4fcd569a Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Wed, 25 Sep 2019 05:53:02 -0600 Subject: [PATCH] Fixes #1130 --- .../Integration/Input.Tests.ps1 | 31 +++++++++++++++++++ .../Cmdlets/Inputs/NewInputCommand.cs | 13 ++++++++ 2 files changed, 44 insertions(+) diff --git a/src/UniversalDashboard.UITest/Integration/Input.Tests.ps1 b/src/UniversalDashboard.UITest/Integration/Input.Tests.ps1 index aacdc3f4..60a5b415 100644 --- a/src/UniversalDashboard.UITest/Integration/Input.Tests.ps1 +++ b/src/UniversalDashboard.UITest/Integration/Input.Tests.ps1 @@ -13,7 +13,38 @@ $Server = Start-UDDashboard -Port 10001 -Dashboard (New-UDDashboard -Title "Test $Driver = Start-SeFirefox Describe "Input" { + Context "validate with content\endpoint" { + $Dashboard = New-UDDashboard -Title "Test" -Content { + New-UDInput -Title 'Request' -Validate -Content { + New-UDInputField -Type 'textbox' -Name 'MyField' + New-UDInputField -Type 'textbox' -Name 'MyField2' + } -Endpoint { + param ( + [Parameter(Mandatory)] + $MyField, + [Parameter(Mandatory)] + $MyField2 + ) + } + } + + $Server.DashboardService.SetDashboard($Dashboard) + Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort" + It "should validate required" { + $Element = Find-SeElement -Id 'MyField' -Driver $Driver + Invoke-SeClick -Element $Element -JavaScriptClick -Driver $Driver + Send-SeKeys -Element $Element -Keys '' + + $Element = Find-SeElement -Id 'MyField2' -Driver $Driver + Invoke-SeClick -Element $Element -JavaScriptClick -Driver $Driver + Send-SeKeys -Element $Element -Keys 'a' + + (Find-SeElement -Id 'MyFieldtooltip' -Driver $Driver).getAttribute("textContent") | should be 'MyField is required.' + } + + + } Context "drops to pipeline" { $Dashboard = New-UDDashboard -Title "Test" -Content { diff --git a/src/UniversalDashboard/Cmdlets/Inputs/NewInputCommand.cs b/src/UniversalDashboard/Cmdlets/Inputs/NewInputCommand.cs index c5a7adf2..47fc2569 100644 --- a/src/UniversalDashboard/Cmdlets/Inputs/NewInputCommand.cs +++ b/src/UniversalDashboard/Cmdlets/Inputs/NewInputCommand.cs @@ -149,6 +149,19 @@ protected override void EndProcessing() { var fields = Content.Invoke().Select(m => m.BaseObject).OfType().ToArray(); input.Fields = fields; + + var paramBlockFields = GetFieldsFromParamBlock().ToArray(); + foreach(var field in paramBlockFields) + { + var contentField = input.Fields.FirstOrDefault(m => m.Name.Equals(field.Name, StringComparison.OrdinalIgnoreCase)); + if (contentField != null) + { + contentField.Required = field.Required; + contentField.Endpoint = field.Endpoint; + contentField.ValidationEndpoint = field.ValidationEndpoint; + contentField.ValidationErrorMessage = field.ValidationErrorMessage; + } + } } Log.Debug(JsonConvert.SerializeObject(input));