Element: 重置表单出错:Cannot read property 'resetFields' of undefined

Created on 29 Nov 2016  ·  10Comments  ·  Source: ElemeFE/element

ElementUI version

OS/Browers version

Vue version

Reproduction Link



Steps to reproduce

What is Expected?

What is actually happening?

重置表单出错:Cannot read property 'resetFields' of undefined,表单是动态创建的,比如:

<el-dialog :title="dialogOption.title + dialogOption.block" v-model="dialogOption.visible" size="tiny">
            <el-form ref="formModel" :model="formModel" :rules="rules" label-width="90px">
                <dynamic-form :formModel="formModel" :formFields="formFields" :sources="sources" :rules="rules"></dynamic-form>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click.native="handleCancel">取 消</el-button>
                <el-button type="primary" @click.native="submitForm">确 定</el-button>
            </span>
</el-dialog>
repro

Most helpful comment

@U2Fsd
this.$nextTick(()=>{ this.$refs.ruleForm.resetFields(); });

All 10 comments

刚才又DEGUB了一下,el-dialog组件中动态创建表单元素,如果dialog没有visible出来,
20161129133112-1

如果dialog先visible出来,就没有问题,如图:
20161129133112-2

请给 demo。

Demo地址:http://jsfiddle.net/yd5gc123/
点击按钮后,控制台直接报错,Dialog不能弹出。
ele-20161130133548

Demo 似乎不太对?Dialog 能弹出,并且代码里没调用 resetFields

@Leopoldthecoder Demo被篡改了?

改不了的吧。重新写一个吧。

是的,我也有这个问题,setTimeout里resetFields一下就没问题,上来直接resetFields就会提示 resetFields not defined.

这个 issue 先关掉了。如果能够提供在线 demo,可以再打开。

@Leopoldthecoder

如果 dialog 没有 visible出来的时候不可以调用 resetFields吗?

我这边写了个Demo 在点击按钮2 之前 按钮1 会报Cannot read property 'resetFields' of undefined

https://jsfiddle.net/Lucius_Yeh/rapas1pb/

@U2Fsd
this.$nextTick(()=>{ this.$refs.ruleForm.resetFields(); });

Was this page helpful?
0 / 5 - 0 ratings