How To Validate Select Option With Vee-Validate

TJ Weems picture TJ Weems · Nov 27, 2018 · Viewed 9.5k times · Source

Going through vee-validates documentation I don't see anything for validating select inputs. So my question is can you validate selects? Currently what I try does not display an error message...

Here is the code

<select id="category" v-model="client.category" name="Category Type" v-validate="'required'">
  <option disabled>{{option}}</option>
  <option v-for="category in categories" :key="category.id" :value="category">{{ category }}</option>
 </select>
 <spanv-show="errors.has('Category Type')">{{ errors.first('Category Type') }}</span>

Answer

vamsi picture vamsi · Jul 16, 2019
v-model="client.category" 

v-validate doesn't work if your v-model is a complex object. I'd use strings/numbers to tie option->select and then use some function to model rest of the attributes in the object.