-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWrappedInputsForm.js
More file actions
39 lines (32 loc) · 992 Bytes
/
Copy pathWrappedInputsForm.js
File metadata and controls
39 lines (32 loc) · 992 Bytes
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
import { LitElement, html } from 'lit-element'
import { withForm } from '../../dist/index.js'
class WrappedInputsForm extends LitElement {
createRenderRoot() {
return this
}
render() {
return html`
<h4>Inputs and Form HOCs</h4>
<form method="POST" @submit=${this.handleSubmit}>
<custom-input name="login"></custom-input>
<error-message name="login"></error-message>
<custom-input name="password" type="password"></custom-input>
<error-message name="password"></error-message>
<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('wrapped-inputs-form', enhance(WrappedInputsForm))