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

StringField.tsx

30 lines811 Bytes

1import { FieldError } from './FieldError'
2import type { Accessor } from 'solid-js'
3import type { FieldWithValue } from '@tanstack/solid-form'
4​
5interface StringFieldProps {
6 field: Accessor<FieldWithValue<string>>
7 label: string
8}
9​
10export function StringField(props: StringFieldProps) {
11 return (
12 <label
13 classList={{ validating: props.field().meta.isValidating }}
14 style={{ display: 'block' }}
15 >
16 <span>{props.label}</span>
17 <input
18 name={props.field().name}
19 value={props.field().value}
20 onBlur={props.field().handleBlur}
21 onInput={(event) =>
22 props.field().handleChange(event.currentTarget.value)
23 }
24 aria-invalid={props.field().meta.isInvalid}
25 />
26 <br />
27 <FieldError field={props.field} />
28 </label>
29 )