Open History to see the last commit
1import { LitElement, html } from 'lit'
2import { customElement } from 'lit/decorators.js'
3import { TanStackFormController } from '@tanstack/lit-form'
4import { addressFields } from './address-fields'
5import { emergencyContactFields } from './emergency-contact'
6import { peopleFormOptions } from './shared-form'
7import { textField } from './text-field'
8import './styles.css'
9β
10@customElement('tanstack-people-form')
11export class TanStackPeopleForm extends LitElement {
12 private form = new TanStackFormController(this, {
13 ...peopleFormOptions,
14 onSubmit: ({ value }) => {
15 alert(JSON.stringify(value, null, 2))
16 },
17 })
18β
19 protected createRenderRoot() {
20 return this
21 }
22β
23 render() {
24 return html`
25 <form
26 @submit=${(event: SubmitEvent) => {
27 event.preventDefault()
28 void this.form.api.handleSubmit()
29 }}
30 >
31 <h1>Personal Information</h1>
32 ${this.form.field({ name: 'fullName' }, (field) =>
33 textField(field, 'Full Name'),
34 )}
35 ${this.form.field({ name: 'email' }, (field) =>
36 textField(field, 'Email'),
37 )}
38 ${this.form.field({ name: 'phone' }, (field) =>
39 textField(field, 'Phone'),
40 )}
41 ${addressFields(this.form)} ${emergencyContactFields(this.form)}
42 ${this.form.subscribe(
43 (state) => state.isSubmitting,
44 (isSubmitting) => html`
45 <button type="submit" ?disabled=${isSubmitting}>Submit</button>
46 `,
47 )}
48 </form>
49 `
50 }
51}