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

string-field.ts

25 lines671 Bytes

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