Comments (7)
有代码能复现吗?
from vue-ele-form.
我这边没法复现,没法解决
from vue-ele-form.
请先点击“基础信息”,再点击“提交并关闭”,你就能够看到警告信息了。全部代码在附件里,改造于你的示例,只稍微修改了2处。 https://www.yuque.com/chaojie-vjiel/vbwzgu/ue72yy , 一处修改是 ele-form-group 组件加了 v-if="visable", 二处修改是 formBtns 的回调函数改为 click :()=> { this.visable = false; }
ele-form-group-test.txt
from vue-ele-form.
请看演示图,并没有报错,请确认
from vue-ele-form.
测试了,是因为我删除了 库里的 EleFormGroup.vue 的 第15行 v-if="item.groupId === currentGroupId"
导致的,请问有没有解决办法保留所有的 ele-form 以便于我提交时,一起验证。
from vue-ele-form.
内部不能,只是不适用ele-form的验证,自己在外部验证。vue-ele-form和element-ui form的验证都是使用的async-validator,所以,你在提交的时候,在外面进行验证,方法如下:
<template>
<!-- isShowBackBtn 、formBtns 和 @request 将添加在所有 group 的 ele-form 中 -->
<ele-form-group
:formBtns="formBtns"
:formData="formData"
:groups="groups"
:isShowBackBtn="false"
:request-fn="handleRequest"
activeGroupId="password"
submitBtnText="确定"
></ele-form-group>
</template>
<script>
import Schema from 'async-validator'
export default {
name: 'Group',
data () {
return {
// rules不需要绑定了
rules: {
name: { required: true, message: '姓名必填' },
age: { type: 'number', min: 20, message: '年龄大于20岁' },
newPassword: { required: true, message: '新密码必填' }
},
// 你如果一起提交, formData就写在这里
formData: {},
groups: [
{
groupId: 'base',
groupLabel: '基础信息',
form: {
// 该分组的 ele-form 属性中的 form-desc
formDesc: {
name: {
type: 'input',
label: '姓名'
},
age: {
type: 'number',
label: '年龄'
}
},
submitBtnText: '发起'
// 这里面不要写formData
}
},
{
groupId: 'password',
groupLabel: '密码',
form: {
formDesc: {
oldPassword: {
type: 'password',
label: '旧密码'
},
newPassword: {
type: 'password',
label: '新密码'
},
confirmPassword: {
type: 'password',
label: '确认密码'
}
}
// 这里面不要写formData
}
}
],
formBtns: [
{
text: '提交并关闭',
click: () => {
console.log('点我了')
this.visable = false
}
}
]
}
},
methods: {
handleRequest (data) {
// 返回一个promise, 参考: https://www.yuque.com/chaojie-vjiel/vbwzgu/zbu9mn#DmTaP
return new Promise((resolve, reject) => {
var validator = new Schema(this.rules)
validator.validate(data, (errors, fields) => {
if (errors) {
// 出现错误
// 弹窗 或 做其它处理
const messageArr = errors.map((item) => {
return this.$createElement('div', { style: { marginBottom: '8px' } }, item.message)
})
this.$notify.error({
title: '表单错误',
message: this.$createElement(
'div',
{ style: { minWidth: '300px', marginTop: '12px' } },
messageArr
)
})
// reject
reject(new Error())
} else {
// 无错误
resolve()
}
})
})
}
}
}
</script>
记得把这个方法封装起来,要不然你每次都得写
from vue-ele-form.
这样也不需要删除 v-if 判断了
from vue-ele-form.
Related Issues (20)
- 插槽功能对驼峰命名的字段不支持
- type=radio问题
- label-width获取不到宽度会报错误
- type=date时间范围选择v-model失效 HOT 2
- type="date"放在最后会导致样式错误
- 项目中引入f-render无法运行项目
- 插槽slot Uncaught TypeError: h is not a function
- 插槽slot Uncaught TypeError: h is not a function
- 支持vue3吗
- 如何全局设置dialog组件?(比如全局设置close-on-click-modal) HOT 2
- optionsLinkageFields 判断不了arr
- select组件, 下拉选项通过prop映射成非默认的text 和 value 的时候, 设置options的 attrs: {disabled: true} 不生效
- vue 双向绑定失效
- `image-uploader` 的 `multiple` 不起作用
- Vue 3 support HOT 1
- 类型定义没有更新 HOT 1
- ele-table-editor的content.no.change事件拿不到回调中的val值 (change事件是动态添加的) HOT 1
- eleFormCascader无法获取到options placeholder为undifined HOT 2
- ele-form-section 表格和动态表单的问题 HOT 1
- type为text时,修改值没有立即生效 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-ele-form.