1

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.." />

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.