element icon indicating copy to clipboard operation
element copied to clipboard

表单验证的一个bug

Open cfking opened this issue 9 years ago • 6 comments

当使用v-if使带有校验规则的输入项隐藏时,会使后面的输入项目校验失效,以下是触发条件: 1、被隐藏的输入项目使用了自定义校验规则 2、被隐藏的输入项的下一个输入项目没有设置校验

https://jsfiddle.net/ygo78r17/3/

_20170320094452 _20170320094500

另外上面的代码还有一个问题,当有隐藏时点重置表单,会报错 Uncaught TypeError: Cannot read property 'indexOf' of undefined

cfking avatar Mar 20 '17 01:03 cfking

。。。

cfking avatar Mar 22 '17 01:03 cfking

用 div 标签把它们包裹起来,或者直接在 div 标签上用 v-if ,不用 template 之前在使用 e-tag 的时候碰到过类似的问题

<template v-if="!defaultpwd" >
         <div>
  <el-form-item label="密码" prop="pass" >
    <el-input type="password" v-model="ruleForm2.pass" auto-complete="off"></el-input>
  </el-form-item>
  <el-form-item label="确认密码" prop="checkPass" >
    <el-input type="password" v-model="ruleForm2.checkPass" auto-complete="off"></el-input>
  </el-form-item>
           </div>
  </template>

ilvsx avatar Mar 22 '17 17:03 ilvsx

Hello, this issue has been closed because it does not conform to our issue requirements. Please submit issues with issue-generator. More info can be found in #3693.

element-bot avatar Mar 24 '17 02:03 element-bot

我本地也遇到了这个问题。尤其是属性是多级的时候。一打包到线上就完蛋 image

image

ifredom avatar Dec 20 '18 09:12 ifredom

为每项添加 key 即可解决

lyon007 avatar Apr 12 '19 08:04 lyon007

solution ✅

unique key


    <template v-if="isShowPrice">
-      <el-form-item class="is-required" label="出价" prop="price"
+      <el-form-item class="is-required" label="出价" prop="price"  key="price"
            :rules="[
                {
                    required: true,
                    message: '请输入出价,
                    trigger: 'blur',
                    validator:  priceValidate,
                },
            ]">
            <el-input
                class="price"
                style="width: 300px;"
                placeholder="请输入出价"
                v-model="ruleForm.price">
                <span slot="suffix" class="custom-suffix">元</span>
            </el-input>
        </el-form-item>
    </template>

xgqfrms avatar Nov 16 '21 04:11 xgqfrms