当前位置: 首页 > news >正文

表单多个输入框校验

表单里一层for循环里多个输入框校验

// 数据结构:dynamicValidateForm:{domains: [{msg:'',content:''},....]}
// model绑定的必须是个对象
<a-form-model:labelCol="{ span: 12 }"ref="dynamicValidateForm"@submit="handleSubmit":model="dynamicValidateForm"
><a-col v-for="(domain, index) in dynamicValidateForm.domains" :key="index">// prop字符串,必须是循环的key值(例如 domains)+index+要校验的值(例如:msg)。<a-form-model-item :prop="'domains.' + index + '.msg'" :rules="{required: true,message: '' }"><a-input v-model="domain.msg" placeholder="请输入" class="ml-10 mr-10 w-100" /></a-form-model-item><a-form-model-item :prop="'domains.' + index + '.content'" :rules="{required: true,message: '' }"><a-input v-model="domain.content" placeholder="请输入" class="ml-10 mr-10 w-100" /></a-form-model-item></a-col>
</a-form-model>

两层for循环里多个输入框校验

// 数据结构: dynamicValidateForm: {domains:[
//             {domain: [{msg:''},....]},
//             {domain: [{msg:''},....]},
//             {domain: [{msg:''},....]},
//             .....
//           ]},
// model绑定的必须是个对象
<a-form-model:labelCol="{ span: 12 }"ref="dynamicValidateForm"@submit="handleSubmit":model="dynamicValidateForm"
><a-row v-for="(domain, index) in dynamicValidateForm.domains" :key="index"><a-col v-for="(item,index2) in domain.domain" :key="index2">// prop字符串,拼接<a-form-model-item  :prop="'domains.' + index + '.domain.' + index2 + '.msg'" :rules="{required: true,message: ''  }"><a-input v-model="item.msg" placeholder="请输入" class="ml-10 mr-10 w-100" /></a-form-model-item></a-col></a-row>
</a-form-model>

// 如果需求要输入框报红,输入后马上变正常,validate-status可以实现

rules规则

<a-form-model :rules="formRules" :model="dynamicValidateForm"><a-form-model-item v-for="(domain, index) in dynamicValidateForm.domains" :key="index"><a-input v-model="domain.score"  placeholder="请输入" class="ml-10 mr-10 w-100" /></a-form-model-item>
</a-form-model// formRules要和dynamicValidateForm.domains,结构一一对应,才能正常校验
formRules:{// domains是重点,0是变量,score是要校验的对象'domains.0.score': [{ required: true, message: '请输入积分', trigger: 'blur' }],
}

http://www.mrgr.cn/news/35794.html

相关文章:

  • 外网SpringBoot项目迁移到内网无法加载maven依赖
  • 逆概率加权(R和Python案例)
  • implementation ‘com.lxj:xpopup:2.2.1‘失败
  • 【Linux】驱动的基本架构和编译
  • TON生态系统开发指南:从零开始构建你的Web3应用
  • 手撕Transformer之Embedding Layer
  • 基于pdf.js实现对pdf预览、批注功能、 保存下载pdf,适配H5,平板 踩坑记录
  • 【鸿蒙】HarmonyOS NEXT开发快速入门教程之ArkTS语法装饰器(上)
  • ntpdate同步配置文件调整详解
  • 聊一聊软件系统性能测试的重要性
  • dspic33F Mplab IDE V8.92内存使用情况
  • SD1.5的遗产
  • 数据结构:Heap堆应用(堆排序,TOP-K问题)手把手带你入门数据结构~
  • 电脑如何录屏?无水印、高清晰度电脑录屏教程
  • 国产长芯微LPA8304对数放大器完全P2P替代AD8304
  • AI产品经理面试题整理【已拿offer】
  • 如何构建智能应用:深入探索Langchain的强大功能与应用潜力
  • 电脑桌面归纳小窗口如何设置?电脑桌面一键整理工具分享!
  • android和ios双端应用性能的测试工具
  • 开放式耳机对耳朵的伤害小?四大专业品牌蓝牙耳机推荐