Custom validations on multi select not getting Array
See original GitHub issueI’m trying to validate a “select multiple” input using a custom validation in the register callback like so
<select
name="multiSelect"
multiple
ref={register({
validate: value => Array.isArray(value) && value.length > 1
})}
>
<option value="opt1">Option 1</option>
<option value="opt2">Option 2</option>
<option value="opt3">Option 3</option>
<option value="opt4">Option 4</option>
</select>
However, the value
passed to the validator function is always a String, the value of which is the topmost selected option
.
Codesandbox available here https://codesandbox.io/embed/react-hook-form-1m47u
Is this a bug, or am I doing something wrong?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Multi Select Custom Validation Rule - jquery - Stack Overflow
One of the reasons your validation is not working is because you are calling the .validate() method twice on the same form. You...
Read more >Validation for multiple select - Laracasts
My form like below : what i need to give validation minimum should select one item ... Laravel doesn't have much of a...
Read more >[1.3] Multiple select and validation failure (how to properly ...
Hi,. i want to use a "multiple" select (a select box where you can check several options), so i create a Phalcon\Forms\Select element...
Read more >jQuery validation of select elements where multiple=”multiple”
To this, we want to add some validation to make sure that at least one element in the list is selected when the...
Read more >Array: Single Select vs. Multi-Select - Knowledgebase
Using the ARRAY custom field on Honeycommb you can either decide if you'd like the field to be a multiple check-box or a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks releasing tonight 🤗
Wow, that was fast! 💪
Thanks!