mobx-react-form
Advanced tools
Comparing version 1.13.8 to 1.13.9
@@ -35,2 +35,18 @@ 'use strict'; | ||
var _get2 = require('lodash/get'); | ||
var _get3 = _interopRequireDefault(_get2); | ||
var _startsWith2 = require('lodash/startsWith'); | ||
var _startsWith3 = _interopRequireDefault(_startsWith2); | ||
var _filter2 = require('lodash/filter'); | ||
var _filter3 = _interopRequireDefault(_filter2); | ||
var _has2 = require('lodash/has'); | ||
var _has3 = _interopRequireDefault(_has2); | ||
var _trimEnd2 = require('lodash/trimEnd'); | ||
@@ -225,11 +241,18 @@ | ||
if (!(0, _isUndefined3.default)($field)) { | ||
if (!(0, _isNull3.default)(val)) { | ||
if ((0, _isUndefined3.default)(val.fields)) $field.set('value', val);else $this.deepUpdate(val.fields, $fullPath); | ||
} | ||
if (!(0, _isUndefined3.default)($field) && !(0, _isNull3.default)(val)) { | ||
if ((0, _isUndefined3.default)(val.fields)) $field.set('value', val);else $this.deepUpdate(val.fields, $fullPath); | ||
} else { | ||
// create fields | ||
var cpath = (0, _trimEnd3.default)(path.replace(new RegExp('/[^./]+$/'), ''), '.'); | ||
var container = $this.select(cpath, null, false); | ||
if (!(0, _isUndefined3.default)(container)) { | ||
// init filed into the container field | ||
container.initField(key, $fullPath, val, null, true); | ||
// handle nested fields if defined | ||
if ((0, _has3.default)(val, 'fields')) $this.deepUpdate(val.fields, $fullPath); | ||
// handle nested fields if undefined or null | ||
else if ((0, _isUndefined3.default)(val) || (0, _isNull3.default)(val)) { | ||
var $fields = $this.pathToFiledsTree($fullPath); | ||
$this.deepUpdate($fields, $fullPath); | ||
} | ||
} | ||
@@ -240,2 +263,14 @@ } | ||
pathToFiledsTree: function pathToFiledsTree(path) { | ||
var ss = $this.state.struct(); | ||
var structPath = _utils2.default.pathToStruct(path); | ||
var structArray = (0, _filter3.default)(ss, function (item) { | ||
return (0, _startsWith3.default)(item, structPath); | ||
}); | ||
var tree = $this.handleFieldsArrayOfStrings(structArray); | ||
var struct = _utils2.default.pathToStruct(path); | ||
struct = (0, _replace3.default)(struct, new RegExp('\\[]', 'g'), '[0]'); | ||
return $this.handleFieldsNested((0, _get3.default)(tree, struct)); | ||
}, | ||
/** | ||
@@ -242,0 +277,0 @@ Get Fields Props |
@@ -163,3 +163,2 @@ 'use strict'; | ||
// handle array with field struct (strings) | ||
// if (_.isArray(fields) && _.every(fields, _.isString)) { | ||
if (_utils2.default.isStruct(fields)) { | ||
@@ -166,0 +165,0 @@ // save the global struct into state |
{ | ||
"name": "mobx-react-form", | ||
"license": "MIT", | ||
"version": "1.13.8", | ||
"version": "1.13.9", | ||
"author": "Claudio Savino <claudio.savino@me.com> (https://twitter.com/foxhound87)", | ||
@@ -6,0 +6,0 @@ "description": "Automagically manage React forms state and automatic validation with MobX.", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1940283
14071