add optional inputText
alexfernandessd authored 4 years ago
James committed 4 years ago
1 | 1 |
|
2 | 2 |
// TextInputSubtype Accepts email, number, tel, or url. In some form factors, optimized input is provided for this subtype.
|
3 | 3 |
type TextInputSubtype string
|
|
4 |
|
|
5 |
// TextInputOption hndle to optional inputs
|
|
6 |
type TextInputOption func(*TextInputOption)
|
4 | 7 |
|
5 | 8 |
const (
|
6 | 9 |
// InputSubtypeEmail email keyboard
|
|
25 | 28 |
}
|
26 | 29 |
|
27 | 30 |
// NewTextInput constructor for a `text` input
|
28 | |
func NewTextInput(name, label, text string) *TextInputElement {
|
29 | |
return &TextInputElement{
|
|
31 |
func NewTextInput(name, label, text string, options ...TextInputOption) *TextInputElement {
|
|
32 |
t := &TextInputElement{
|
30 | 33 |
DialogInput: DialogInput{
|
31 | 34 |
Type: InputTypeText,
|
32 | 35 |
Name: name,
|
|
34 | 37 |
},
|
35 | 38 |
Value: text,
|
36 | 39 |
}
|
|
40 |
|
|
41 |
for _, opt := range options {
|
|
42 |
opt(&t)
|
|
43 |
}
|
|
44 |
|
|
45 |
return t
|
37 | 46 |
}
|
38 | 47 |
|
39 | 48 |
// NewTextAreaInput constructor for a `textarea` input
|
9 | 9 |
name := "internalName"
|
10 | 10 |
label := "Human Readable"
|
11 | 11 |
value := "Pre filled text"
|
12 | |
textInput := NewTextInput(name, label, value)
|
|
12 |
optional := true
|
|
13 |
textInput := NewTextInput(name, label, value, optional)
|
13 | 14 |
assert.Equal(t, InputTypeText, textInput.Type)
|
14 | 15 |
assert.Equal(t, name, textInput.Name)
|
15 | 16 |
assert.Equal(t, label, textInput.Label)
|
16 | 17 |
assert.Equal(t, value, textInput.Value)
|
|
18 |
assert.Equal(t, optional, textInput.Optional)
|
17 | 19 |
}
|
18 | 20 |
|
19 | 21 |
func TestNewTextAreaInput(t *testing.T) {
|