Select
The select element is used to create a drop-down list.
It accepts, as props, any html attribute listed at: Html Select Attributes.
Props
name
: string
- A field's name in Usetheform state.
- If your Select is rendered within a
<Collection array />
, name is not allowed as a prop.
index
: string
- A field's index in an array Collection.
- index is only allowed if your Select is rendered within a
<Collection array />
.
value
: string
- Specifies the initial value of a select element.
touched
: boolean
A field that has been touched/visited. Default value of false.
If true, validation messages (sync and async) will be shown but only when the event onBlur of the field is triggered by a user action.
multiple
: boolean
- When present, it specifies that multiple options can be selected at once. Default value of false.
reducers
: array | function
(nextValue, prevValue, formState) => nextValue
- An array whose values correspond to different reducing functions.
- Reducer functions specify how the Select's value changes.
innerRef
: object (a mutable ref object)
- When you need to access the underlying DOM node created by Select (e.g. to call focus), you can use a ref to store a reference to the select dom node.
const ref = useRef(null)<Select innerRef={ref} name="test">...options...</Select>
Basic usage
Single options
import { Form, Select } from 'usetheform'
- {} 0 keys
Multiple options
- {} 0 keys
Reducers
import { Form, Select } from 'usetheform'
- {} 0 keys
Validation - Sync
import { useValidation } from 'usetheform'
- {} 0 keys
Validation - Async
import { useAsyncValidation, useForm } from 'usetheform'const Submit = () => {const { isValid } = useForm();return (<button disabled={!isValid} type="submit">Submit</button>);};
- {} 0 keys