Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

text-field.ts

23 lines696 Bytes

1import { html } from 'lit'
2import type { FieldWithValue } from '@tanstack/lit-form'
3​
4export function textField(field: FieldWithValue<string>, label: string) {
5 return html`
6 <div>
7 <label>
8 <span>${label}</span>
9 <input
10 name=${field.name}
11 .value=${field.value}
12 @input=${(event: InputEvent) =>
13 field.handleChange((event.currentTarget as HTMLInputElement).value)}
14 @blur=${() => field.handleBlur()}
15 aria-invalid=${field.meta.isInvalid ? 'true' : 'false'}
16 />
17 </label>
18 ${field.errors.map(
19 (error) => html`<div class="error" role="alert">${error.message}</div>`,
20 )}
21 </div>
22 `