form icon indicating copy to clipboard operation
form copied to clipboard

form.getFieldValue method will create a new field in fieldMeta

Open lulut opened this issue 7 years ago • 2 comments

form.getFieldValue method will create a new field in fieldMeta. This cause an issue when set an array value to the field later.

version 2.2.x getFieldMeta(name) { this.fieldsMeta[name] = this.fieldsMeta[name] || {}; return this.fieldsMeta[name]; }

version 1.4.x getValueFromFieldsInternal(name, fields) { const field = fields[name]; if (field && 'value' in field) { return field.value; } const fieldMeta = this.fieldsMeta[name]; return fieldMeta && fieldMeta.initialValue; }

lulut avatar Jul 23 '18 09:07 lulut

https://codesandbox.io/s/50x3l7y59n

Steps to reproduce

  1. click "Add field" button
  2. new row will be created with no issue
  3. click "Error Button" button, no impacts to the function since the "list" variable has been initialized as an Array correctly.
  4. reload the page
  5. this time click "Error Button" first.
  6. a new field "list" will be added to fieldMeta
  7. click "Add field" button
  8. error occurred because list is an 'object' instead of 'Array'

lulut avatar Jul 24 '18 01:07 lulut

This bug stumped me for two days. I definitely did not expect a method named "getFieldValue" to create a new field!!!

Woodz avatar Jun 30 '21 10:06 Woodz