diff --git a/src/createBaseForm.js b/src/createBaseForm.js index 911c594b..ee25ba39 100644 --- a/src/createBaseForm.js +++ b/src/createBaseForm.js @@ -6,6 +6,7 @@ import { isEmptyObject, flattenArray, getNameKeyObj, getNameKeyStr, flatFieldNames, clearVirtualField, + setObject, } from './utils'; import AsyncValidator from 'async-validator'; import warning from 'warning'; @@ -333,8 +334,7 @@ function createBaseForm(option = {}, mixins = []) { if (fieldsMeta.hasOwnProperty(fieldKey)) { const nameKeyObj = getNameKeyObj(fieldKey); if (nameKeyObj.name === name && nameKeyObj.key) { - ret[nameKeyObj.key] = - this.getValueFromFieldsInternal(fieldKey, fields); + setObject(nameKeyObj.key, this.getValueFromFieldsInternal(fieldKey, fields), ret) } } } diff --git a/src/utils.js b/src/utils.js index 413d4a58..5c0b7f69 100644 --- a/src/utils.js +++ b/src/utils.js @@ -110,6 +110,16 @@ export function getNameKeyObj(str) { }; } +export function setObject(str, value, context) { + var parts = str.split(NAME_KEY_SEP), + p = parts.pop(); + // if object && string has another part && we've looped less than 100 times + for(var i=0, j; context && (j=parts[i]) && i<100; i++){ + context = (j in context ? context[j] : context[j]={}); + } + return context && p ? (context[p]=value) : undefined; // Object +} + export function flatFields(fields_, fieldsMeta) { const fields = { ...fields_ }; Object.keys(fields).forEach((k) => {