question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom validations on multi select not getting Array

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Aug 26, 2019

Thanks releasing tonight 🤗

1reaction
bostromcommented, Aug 26, 2019

Wow, that was fast! 💪

Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found