-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(form): add support for validator, etc ...
- Loading branch information
Showing
15 changed files
with
504 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
|
||
[Test_Form_Rendering - 1] | ||
[Test_Form_Rendering_Error - 1] | ||
<form action="POST" action="" encoding=""> | ||
<label class="" style="" for="name">name</label> | ||
<input name="name" type="text" value="John Doe" id="name" placeholder="Enter the name" required readonly autofocus size="10" maxlength="100" minlength="10" max="100" min="10" step="10" pattern="^[a-z]+$" autocomplete="on"> | ||
<label class="" style="" for="email">email</label> | ||
<input name="email" type="email" value="john.doe@gmail.com" id="email"> | ||
<label for="position">position</label> | ||
<input name="position" type="number" value="1" id="position"> | ||
<span>The position</span> | ||
|
||
</form> | ||
--- | ||
|
||
[Test_Form_Rendering_Error - 2] | ||
<form action="POST" action="" encoding=""> | ||
<label for="position">position</label> | ||
<input name="position" type="number" value="foo" id="position"> | ||
<span>The position</span> | ||
<ul> | ||
<li>value does not match the expected type</li> | ||
<li>the value is not a valid email</li> | ||
</ul> | ||
|
||
</form> | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright © 2014-2023 Thomas Rabaix <thomas.rabaix@gmail.com>. | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package form | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_Date_Marshalling(t *testing.T) { | ||
field := CreateFormField() | ||
form := CreateForm(nil) | ||
|
||
field.InitialValue = time.Date(2022, time.April, 1, 1, 1, 1, 1, time.UTC) | ||
|
||
dateMarshal(field, form) | ||
|
||
assert.Equal(t, "2022-04-01", field.Input.Value) | ||
} | ||
|
||
func Test_Date_Unmarshalling(t *testing.T) { | ||
field := CreateFormField() | ||
field.Input.Id = "Date" | ||
field.Input.Name = "Date" | ||
|
||
form := CreateForm(nil) | ||
|
||
field.InitialValue = time.Date(2022, time.April, 1, 1, 1, 1, 1, time.UTC) | ||
|
||
v := url.Values{ | ||
"Date": []string{"2022-04-01"}, | ||
} | ||
|
||
dateUnmarshal(field, form, v) | ||
|
||
expectedDate := time.Date(2022, time.April, 1, 0, 0, 0, 0, time.UTC) | ||
|
||
assert.Equal(t, expectedDate, field.SubmitedValue) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.