-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNativeInputsForm.js
More file actions
120 lines (107 loc) · 2.98 KB
/
Copy pathNativeInputsForm.js
File metadata and controls
120 lines (107 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { LitElement, html } from 'lit-element'
import { withForm } from '../../dist/index.js'
class NotWrappedInputsForm extends LitElement {
createRenderRoot() {
return this
}
static get properties() {
return {
values: { type: Object },
errors: { type: Object },
touched: { type: Object }
}
}
render() {
return html`
<h4>Native inputs</h4>
<form method="POST" @submit=${this.handleSubmit}>
<input
id="login"
@input=${this.handleChange}
@change=${this.handleChange}
@blur=${this.handleBlur}
.value=${this.values.login}
/>
${this.errors.login && this.touched.login
? html`<p class="error-message">${this.errors.login}</p>`
: null}
<input
id="password"
type="password"
@input=${this.handleChange}
@change=${this.handleChange}
@blur=${this.handleBlur}
.value=${this.values.password}
/>
${this.errors.password && this.touched.password
? html`<p class="error-message">${this.errors.password}</p>`
: null}
<label>
<input
@change=${this.handleChange}
?checked=${this.values.radio == 1}
name="radio"
type="radio"
value="1"
/>
1
</label>
<label
><input
@change=${this.handleChange}
?checked=${this.values.radio == 2}
name="radio"
type="radio"
value="2"
/>
2
</label>
<label>
<input
@change=${this.handleChange}
?checked=${this.values.radio == 3}
name="radio"
type="radio"
value="3"
/>
3
</label>
<textarea name="textarea" cols="20" @change=${this.handleChange}>
</textarea>
<select name="select" @change=${this.handleChange}>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select
name="multiple"
size="5"
?multiple=${true}
@change=${this.handleChange}
>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<button type="submit">Submit</button>
</form>
`
}
}
const enhance = withForm({
initialValues: { login: '', password: '' },
onSubmit: values => console.log(values),
validationSchema: {
login: value => {
if (!value) return 'Required'
},
password: value => {
if (value.length < 5) return 'Must be more than 5 letters'
}
}
})
customElements.define('not-wrapped-inputs-form', enhance(NotWrappedInputsForm))