antdesign 表单设置默认值 modal

antdesign 表单设置默认值(antd4.x)

使用setFieldsValue 是通过ref来进行操作,如下所示:

//组件写法
 <Form
     ref={this.formRefOne}
      {...layout}
      initialValues={{ remember: true }}
      onFinish={onFinish}
      onFinishFailed={onFinishFailed}
  >
      <Form.Item
          label="标&emsp;&emsp;&nbsp;题"
          name="title"
          rules={[{
              required: true,
              message: '请输入标题'
          }]}
      >
</Form>      

创建ref(切记 一个ref只能供一个form表单使用 有多个form表单则创建多个ref即可 如果多个form表单调用同一个ref 则只能一个form表单生效)

//以函数方式 创建一个ref
formRef = React.createRef();

调用赋值

this.formRef.current.setFieldsValue( {
            title: null,
            time: ''
        } )

在modal中使用

// forceRender={true} 表示强制渲染 这样当modal关闭的时候 也能访问到modal中的form表单
<Modal forceRender={true}>
  ...
</Modal>  
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值