I use the express validator to check the POST data in my express application. I have a form in which there is a choice where the user can select several options:
<select name="category" multiple id="category">
<option value="1">category 1 </option>
.......
</select>
The payload after submitting the form shows me this if I select multiple values:
...&category=1&category=2&....
Now in my Express application, I am trying to test it as follows:
req.checkBody('category', 'category cannot be empty').notEmpty();
But even after sending multiple values, I always get an error message - category cannot be empty. If I print my variable as req.body.category[0]- I get the data. But somehow Iβm not able to understand how I need to pass this on to my validator.
source
share