Skip to content

Commit

Permalink
Add clear input without toast.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Sep 30, 2019
1 parent 5f58747 commit afb3d19
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 29 deletions.
63 changes: 36 additions & 27 deletions src/UniversalDashboard.Materialize/Components/ud-input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,37 @@ export default class Input extends React.Component {
});
}

clearInput()
{
var fields = this.state.fields.map(function(x) {
if (x.type == "checkbox") {
x.value = false;
}

if (x.type == "textbox") {
x.value = '';
}

if (x.type == "select") {
x.value = '';
}

if (x.type == "password") {
x.value = '';
}

if (x.type == "textarea") {
x.value = '';
}

return x;
})

this.setState({
fields: fields
})
}

onSubmit(e) {
e.preventDefault();

Expand Down Expand Up @@ -97,37 +128,15 @@ export default class Input extends React.Component {
}

res.map(function(x) {
if (x.type === "clear") {
this.clearInput();
}

if (x.type === "toast") {
M.toast({html: x.text, displayLength: x.duration});

if (x.clearInput) {
var fields = this.state.fields.map(function(x) {
if (x.type == "checkbox") {
x.value = false;
}

if (x.type == "textbox") {
x.value = '';
}

if (x.type == "select") {
x.value = '';
}

if (x.type == "password") {
x.value = '';
}

if (x.type == "textarea") {
x.value = '';
}

return x;
})

this.setState({
fields: fields
})
this.clearInput();
}
}

Expand Down
40 changes: 40 additions & 0 deletions src/UniversalDashboard.UITest/Integration/Input.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,46 @@ Describe "Input" {
}
}

Context "clear input" {
$Dashboard = New-UDDashboard -Title "Test" -Content {
New-UDInput -Title "Simple Form" -Id "Form" -Content {
New-UDInputField -Type 'textbox' -Name 'test' -Placeholder 'Test testbox' -DefaultValue "Test"
New-UDInputField -Type 'checkbox' -Name 'test2' -Placeholder 'checkbox'
New-UDInputField -Type 'select' -Name 'test3' -Placeholder 'select' -Values @("Test", "Test2", "Test3") -DefaultValue "Test"
New-UDInputField -Type 'radioButtons' -Name 'test4' -Placeholder @("My Test Value", "My Test Value 2", "My Test Value 3") -Values @("MyTestValue", "MyTestValue2", "MyTestValue3")

New-UDInputField -Type 'password' -Name 'test5' -Placeholder 'Password'
New-UDInputField -Type 'textarea' -Name 'test6' -Placeholder 'Big Box o Text'
New-UDInputField -Type 'switch' -Name 'test7' -Placeholder @("Yes", "No")
} -Endpoint {
param($Test, $Test2, $Test3, $Test4, $Test5, $Test6, $Test7)

New-UDInputAction -ClearInput
}
}

$Server.DashboardService.SetDashboard($Dashboard)
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"

It "have cleared input on toast" {
$Element = Find-SeElement -Id "test" -Driver $Driver
Send-SeKeys -Element $Element -Keys "Hello"

$Element = Find-SeElement -Id "test2" -Driver $Driver
Invoke-SeClick -Element $Element -JavaScriptClick -Driver $Driver

$Button = Find-SeElement -Id "btnForm" -Driver $Driver
Invoke-SeClick -Element $Button

Start-Sleep 1

$Element = Find-SeElement -Id "test" -Driver $Driver
[string]::IsNullOrEmpty($Element.Text) | Should be $true
$Element = Find-SeElement -Id "test2" -Driver $Driver
$Element.Selected | Should be $False
}
}

Context "clear input on toast" {
$Dashboard = New-UDDashboard -Title "Test" -Content {
New-UDInput -Title "Simple Form" -Id "Form" -Content {
Expand Down
10 changes: 8 additions & 2 deletions src/UniversalDashboard/Cmdlets/Inputs/NewInputActionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace UniversalDashboard.Cmdlets.Inputs
{
[Cmdlet(VerbsCommon.New, "UDInputAction")]
[Cmdlet(VerbsCommon.New, "UDInputAction", DefaultParameterSetName = "clear")]
public class NewInputActionCommand : PSCmdlet
{
[Parameter(Mandatory = true, ParameterSetName = "toast")]
Expand All @@ -19,7 +19,7 @@ public class NewInputActionCommand : PSCmdlet
[Parameter(Mandatory = true, ParameterSetName = "content")]
public object Content { get; set; }

[Parameter(ParameterSetName = "toast")]
[Parameter()]
public SwitchParameter ClearInput { get; set; }

protected override void EndProcessing()
Expand All @@ -34,6 +34,12 @@ protected override void EndProcessing()
inputAction.Duration = Duration;
}

if (ParameterSetName == "clear")
{
inputAction.Type = InputAction.Clear;
inputAction.ClearInput = ClearInput;
}

if (ParameterSetName == "redirect")
{
inputAction.Type = InputAction.Redirect;
Expand Down
1 change: 1 addition & 0 deletions src/UniversalDashboard/Models/InputAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace UniversalDashboard.Models
{
public class InputAction
{
public static string Clear => "clear";
public static string Toast => "toast";
public static string Redirect => "redirect";
public static string Content => "content";
Expand Down

0 comments on commit afb3d19

Please sign in to comment.