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

text-fields.tsx

27 lines734 Bytes

1import { For } from 'solid-js'
2import type { Accessor } from 'solid-js'
3import type { FieldWithValue } from '@tanstack/solid-form'
4​
5export default function TextField(props: {
6 field: Accessor<FieldWithValue<string>>
7 label: string
8}) {
9 return (
10 <div>
11 <label>
12 <div>{props.label}</div>
13 <input
14 value={props.field().value}
15 onInput={(event) =>
16 props.field().handleChange(event.currentTarget.value)
17 }
18 onBlur={props.field().handleBlur}
19 aria-invalid={props.field().meta.isInvalid}
20 />
21 </label>
22 <For each={props.field().errors}>
23 {(error) => <div style={{ color: 'red' }}>{error.message}</div>}
24 </For>
25 </div>
26 )