element 表格嵌套表單驗證指定行的操作方法
elementui表格嵌套動態(tài)表單,單獨驗證某一行輸入項是否符合校驗規(guī)則;
input動態(tài)綁定校驗 :prop="'imgTable.' + scope.$index + '.bxName'"
<el-form :model="formTable" ref="formTable" inline size="small">
<el-table :data="formTable.imgTable" :show-header="false" max-height="500">
<el-table-column>
<template slot-scope="scope">
<el-form-item :prop="'imgTable.' + scope.$index + '.bxName'" :rules="{
required: true, message: '請輸入報銷項目', trigger: 'blur'}">
<el-input v-model="scope.row.bxName" placeholder="請輸入報銷項目"></el-input>
</el-form-item>
</template>
</el-table-column>
</el-table>
</el-form>想要驗證表單指定項需要使用 validateField,官網(wǎng)文檔傳參 Function(props: array | string, callback: Function(errorMessage: string)), array類型可以驗證多個項。
let validarr = []
this.$refs['formTable'].validateField([
`imgTable.${i}.bxName`, `imgTable.${i}.bxMoney`, `imgTable.${i}.bxDate`
],(err) => {
validarr.push(!err)
})
console.log(validarr.every(item=>{return item == true}))error返回值為rules中的message內(nèi)容,如果驗證通過返回空;這里 !err = true
需要注意的是,驗證項傳參為數(shù)組時,validateField會多次返回error,不會一次返回所有項的驗證結(jié)果,如果在error callback中調(diào)用其他方法會多次調(diào)用;所以額外增加了validarr的遍歷判斷所有項都驗證通過
到此這篇關(guān)于element 表格嵌套表單驗證指定行的文章就介紹到這了,更多相關(guān)element 表格嵌套表單驗證內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Bootstrap + Vue.js實現(xiàn)添加刪除數(shù)據(jù)示例
本篇文章主要介紹了使用Bootstrap + Vue.js實現(xiàn) 添加刪除數(shù)據(jù)示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-02-02
Vue使用Antd中a-table實現(xiàn)表格數(shù)據(jù)列合并展示示例代碼
文章介紹了如何在Vue中使用Ant?Design的a-table組件實現(xiàn)表格數(shù)據(jù)列合并展示,通過處理函數(shù)對源碼數(shù)據(jù)進(jìn)行操作,處理相同數(shù)據(jù)時合并列單元格2024-11-11

