Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 Form getFieldDecorator 遇到的问题 #3976

Closed
zhaotoday opened this issue Nov 23, 2016 · 18 comments
Closed

使用 Form getFieldDecorator 遇到的问题 #3976

zhaotoday opened this issue Nov 23, 2016 · 18 comments

Comments

@zhaotoday
Copy link

zhaotoday commented Nov 23, 2016

<Form.Item
  labelCol={{span: 2}}
  wrapperCol={{span: 20}}
  label="内容"
  required
  hasFeedback>
  {getFieldDecorator('content', {
    rules: [{
      required: true,
      message: '请输入内容'
    }],
  })(
    <Editor afterChange={this._handleAfterChange} />
  )}
</Form.Item>

Editor 是我自定义的组件,程序可以执行但是报了个警告:
Warning: getFieldDecorator will override value, so please don't set value directly and use setFieldsValue to set it.

@benjycui
Copy link
Contributor

Editor.defaultProps 里面应该是定义了 value,得去掉。

目前没想到办法区分用户自行设置的属性和默认属性。

@zhaotoday
Copy link
Author

有点坑,不过构建后的代码没有警告,先这样了。

@leaflike91
Copy link

怎么解决的啊大神

@xiaoshuai
Copy link

改成用initialValue?

@FE-Mars
Copy link

FE-Mars commented May 18, 2017

有办法解决么

@leaflike91
Copy link

benjycui 说的对

@lileilei
Copy link

lileilei commented Jun 22, 2017

upload 组件

<FormItem
              {...formItemLayout}
              label="图片"
            >
              {getFieldDecorator('picurls', {
                valuePropName: 'fileList',
                initialValue: item ? item.picurls : [],
                getValueFromEvent: this.handleChange
              })(
                <Upload
                  action={pkage.imgServer+"upload"}
                  listType="picture-card"
                  data={{prx:'jpg,png,gif,jpeg'}}
                  onPreview={this.handlePreview}
                  onChange={this.handleChange}
                >
                  {uploadButton}
                </Upload>
              )}
            </FormItem>

初始化的值格式,与后添加的值格式,getFieldsValue 获取的两种数据类型

@xyzdata
Copy link

xyzdata commented Jul 12, 2017

too much bugs!

type="number" === initialValue: record.pname,

must keep input type same

    <FormItem
        label={<span className="left-spaces">角色编码:</span>}
        style={{}}
        >
        {
            getFieldDecorator('roleCode', {
                initialValue: record.pname,
                rules: [{ required: false, message: '角色编码' }],
            })
            (
                <Input 
                    prefix={<Icon type="user" style={{ fontSize: 13 }} />} 
                    type="number" 
                    placeholder="角色编码" 
                    />
            )
        }
    </FormItem>

@YoRenChen
Copy link

使用setFieldsValue 里面的属性的设置来代替Value?

@lizhengnacl
Copy link

getFieldDecorator的参数valuePropName指向的属性,不能出现在自定义组件的defaultProps中,valuePropName默认指向value

@navono
Copy link

navono commented Nov 15, 2017

应该在getFieldDecorator的时候,设置initialValue
然后把自定义控件中的value属性删除。
这样就没有警告了。

@fongfai
Copy link

fongfai commented Jan 20, 2018

Input 组件设置 valuePropName: 'disabled' , 也有问题;
设置这个报警告 只能用setFieldsValue, 明明我用的就是setFieldsValue;
只能用setState,才能正确控制表单内的Input的disabled

@CodePlayer7
Copy link
Contributor

antd 里面很多的组件都是内部用state去管理,state根据控制层的props变化,这样state可以有设置默认值等各种行为

@nazhenhuiyi
Copy link

nazhenhuiyi commented Apr 18, 2019

解决思路是在原来的设置了 defaultProps 的组件再包装一层,可以避免这个 warning。
感觉这个 warning 校验的不是很好。

@hellomrbigshot
Copy link

getFieldDecorator的参数valuePropName指向的属性,不能出现在自定义组件的defaultProps中,valuePropName默认指向value

对的,我就是自定义 markdown 编辑器设置了 defaultProps 后出现了这个 warning。

@Shenchuanhuan
Copy link

Shenchuanhuan commented Oct 24, 2019

Editor.defaultProps 里面应该是定义了 value,得去掉。

目前没想到办法区分用户自行设置的属性和默认属性。

去掉了defaultProps里的value,但是报了这种错,有设置initialValue且initialValue不为undefined:

The prop `value` is marked as required in `BackendInputNumber`, but its value is `undefined`

大佬能解答一下吗?自定义组件只是封装了一下inputNumber。另外,input和inputNumber包了个其它元素,getFieldDecorator就没法对它赋值和onChange操作了?

@hellomrbigshot
Copy link

Editor.defaultProps 里面应该是定义了 value,得去掉。
目前没想到办法区分用户自行设置的属性和默认属性。

去掉了defaultProps里的value,但是报了这种错,有设置initialValue且initialValue不为undefined:

The prop `value` is marked as required in `BackendInputNumber`, but its value is `undefined`

大佬能解答一下吗?自定义组件只是封装了一下inputNumber。另外,input和inputNumber包了个其它元素,getFieldDecorator就没法对它赋值和onChange操作了?

用法问题吧,我的在 antd 表单中使用组件的方式是这样的

<Form.Item>
        {getFieldDecorator('content', {
             rules: [{ required: true, message: '请输入文章内容' }],
             initialValue: articleDetail.content
         })(<MEditor theme='dark'/>)}
</Form.Item>

你的 initialValue 在组件初始化的时候是不是未定义?

@yhcui01
Copy link

yhcui01 commented May 22, 2020

index.js:1 Warning: getFieldDecorator will override value, so please don't set value directly and use setFieldsValue to set it.
我也遇到这个错误了,自定义组件报的错,我是value 值设置出的问题自定义的value 值没有传入参数 undefind 就会出这个错误。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests