Giter VIP home page Giter VIP logo

Comments (7)

dream2023 avatar dream2023 commented on July 23, 2024

有代码能复现吗?

from vue-ele-form.

dream2023 avatar dream2023 commented on July 23, 2024

我这边没法复现,没法解决

from vue-ele-form.

jackiehe avatar jackiehe commented on July 23, 2024

请先点击“基础信息”,再点击“提交并关闭”,你就能够看到警告信息了。全部代码在附件里,改造于你的示例,只稍微修改了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.

dream2023 avatar dream2023 commented on July 23, 2024

issue

请看演示图,并没有报错,请确认

from vue-ele-form.

jackiehe avatar jackiehe commented on July 23, 2024

测试了,是因为我删除了 库里的 EleFormGroup.vue 的 第15行 v-if="item.groupId === currentGroupId"
导致的,请问有没有解决办法保留所有的 ele-form 以便于我提交时,一起验证。

from vue-ele-form.

dream2023 avatar dream2023 commented on July 23, 2024

内部不能,只是不适用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.

dream2023 avatar dream2023 commented on July 23, 2024

这样也不需要删除 v-if 判断了

from vue-ele-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.