forms - 如何根据选择字段的 onChange 事件在 vuelidate 中启用所需的验证
问题描述
我必须根据选择字段的 onChange 事件为输入字段启用所需的验证。我在我的项目中使用 vuelidate 包进行表单验证。请提供解决方案来完成它。
我的模板代码如下:
<template>
<section class="page_blk">
<form @submit="submitForm($event)" class="cryp_form">
<div class="input_ctrl_wrp">
<label for="username">Template</label>
<div class="input_select">
<select @change="getTemplate" v-model="$v.adForm.tnc.$model" name="" id="">
<option value="">Select</option>
<option value="New">New</option>
<option :value="term.idTnCTemplate"
v-for="term in termsList"
:key="term.idTnCTemplate">{{term.title}}</option>
</select>
<i class="fal fa-angle-down"></i>
</div>
</div>
<div class="input_ctrl_wrp">
<label for="username">Title</label>
<div class="input_text">
<input v-model="$v.adForm.title.$model" placeholder="" type="text">
</div>
</div>
<div class="input_ctrl_wrp">
<label for="username">Terms Of Trade</label>
<div class="input_textarea">
<textarea v-model="$v.adForm.content.$model" name="" rows="10"></textarea>
</div>
</div>
</form>
</section>
</template>
我的脚本如下:
<script>
import { required,requiredIf, decimal, numeric } from "vuelidate/lib/validators";
export default {
data() {
return {
adForm: {
tnc: '',
title: '',
content: '',
}
}
},
validations: {
adForm: {
tnc: {
required
},
title: {
required
},
content: {
required: requiredIf( (abc) => {
console.log('abc',abc)
return true;
})
},
schedule: {
required
}
}
},
methods: {
submitForm(e) {
},
getTemplate(e) {
}
},
mounted() {
}
}
</script>
如果用户从下拉列表中选择新选项和其他选项,我想将验证切换为标题和内容字段所需的。请提供解决方案来完成它。提前致谢。
解决方案
推荐阅读
- sql - 按多行数据分组
- c# - .NET Core SDK/运行时和 NuGet 包版本必须匹配吗?
- java - 无法使用 Pyspark 将数据框保存到镶木地板
- python - 当我尝试为 Airflow 1.10.10 创建只读用户时,user.commit () 不起作用
- java - 如何从 Linux 上的 java 项目中的 res 文件夹运行 .sh 文件?
- python - 如何使用命名空间将 JSON 转换为 XML?
- php - 通过当前坐标获取所有可用坐标的列表
- django - 带有通用解析器的 Graphene-django 返回列表或字段
- netsuite - 2.0 Suitelet 具有来自 1.0 客户端脚本的自定义功能
- python - Python Closure 不适用于在线解释器