Antd之表单清空操作(一)

handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
        if (!err) {
            console.log('Received values of form: ', values);
        }
    });
    //关键代码,不过这样会带来一个问题,校验时无法显示提示信息,解决方案看第二篇博客
    this.props.form.resetFields();
};

<Form onSubmit={this.handleSubmit} layout='inline'>
    <FormItem label={
        channelIndexTxt ||
        channelLayoutTxt ||
        channelTitleTxt ||
        channelDescriptionTxt ||
        channelEnabledTxt
    }>
        {getFieldDecorator('Channel_Datum', {
            rules: [{required: true, message: '必选项!'}],
        })(
            channelEnabledTxt ?
                <Switch
                    checkedChildren="开"
                    unCheckedChildren="关"
                    defaultChecked
                    onChange={this.handleChange}
                />
                :
                <Input
                    placeholder={'pls input ' + (
                        channelIndexTxt ||
                        channelLayoutTxt ||
                        channelTitleTxt ||
                        channelDescriptionTxt

                    )}

                />
        )}
    </FormItem>
    <Button type="primary" htmlType={'submit'}>修改</Button>
</Form>

版权声明:本文为qq_33733970原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
THE END
< <上一篇
下一篇>>