form.getInputProps(path) returns the props a field needs, so you spread it instead of wiring each handler.
Most fields take value and call onChange with the new value: Select, Slider, NumberInput, DatePicker, TagsInput, Rating, Radio.Group and others.
Input and Textarea call onChange with the event, and getInputProps reads event.target.value for you.
Select, Radio.Group and Slider take the spread.
A checkbox has no value, it has checked. Pass { type: 'checkbox' } and getInputProps returns checked and reads event.target.checked.
Use the checkbox type for boolean fields.
While a field has an error, getInputProps also returns error and errorMessage. Input, Textarea, NumberInput, TagsInput, Select, Checkbox, Radio, Radio.Group, Toggle and Slider show them.
On other fields, such as SegmentedControl, pass only value and onChange, or the extra props reach the DOM as unknown attributes.
type getInputProps = (
path: string,
options?: { type?: 'input' | 'checkbox' }
) => {
value?: any
checked?: boolean
onChange: (valueOrEvent: any) => void
onBlur: () => void
error?: boolean
errorMessage?: string
}
| Type | Returns | Use with |
|---|---|---|
'input' | value, onChange, onBlur, and the error when set | every field that takes a value |
'checkbox' | checked, onChange, onBlur, and the error when set | Checkbox |