Matteo
Matteo

Reputation: 11

Vue validator multiple input field

how can i validate a form group (select + input text) that require at least one of the two with vue-validator.js? Thanks.. e.g.

<select>
<option>Select one..</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
<input type="text" placeholder="Or type here.." />

Upvotes: 1

Views: 1740

Answers (1)

alimfazeli
alimfazeli

Reputation: 101

You should have select and input have the same v-model attribute and then set validation on one of them. like this:

<select v-model="modelName" v-validate:modelName="{required:true}">
<option>Select one..</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
<input v-model="modelName" type="text" placeholder="Or type here.." />
<span v-show="$validation.modelName.required">this field is required</span>

and of course all of your form should be wrapped in a validator component like this:

 <validator name="validation">
 </validator>

but i assume you're already doing this.

Upvotes: 1

Related Questions