Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit 3e13d4c

Browse files
committed
v8.4.0
2 parents c01a4de + fd109c0 commit 3e13d4c

File tree

8 files changed

+69
-10
lines changed

8 files changed

+69
-10
lines changed

dist/formly.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* angular-formly JavaScript Library v8.3.0
2+
* angular-formly JavaScript Library v8.4.0
33
*
44
* @license MIT (http://license.angular-formly.com)
55
*
@@ -157,7 +157,7 @@ return /******/ (function(modules) { // webpackBootstrap
157157

158158
ngModule.constant('formlyApiCheck', _providersFormlyApiCheck2['default']);
159159
ngModule.constant('formlyErrorAndWarningsUrlPrefix', _otherDocsBaseUrl2['default']);
160-
ngModule.constant('formlyVersion', ("8.3.0")); // <-- webpack variable
160+
ngModule.constant('formlyVersion', ("8.4.0")); // <-- webpack variable
161161

162162
ngModule.provider('formlyUsability', _providersFormlyUsability2['default']);
163163
ngModule.provider('formlyConfig', _providersFormlyConfig2['default']);
@@ -367,6 +367,7 @@ return /******/ (function(modules) { // webpackBootstrap
367367
resetModel: apiCheck.func.optional,
368368
updateInitialValue: apiCheck.func.optional,
369369
removeChromeAutoComplete: apiCheck.bool.optional,
370+
parseKeyArrays: apiCheck.bool.optional,
370371
templateManipulators: templateManipulators.optional,
371372
manualModelWatcher: apiCheck.oneOfType([apiCheck.bool, apiCheck.func]).optional,
372373
watchAllExpressions: apiCheck.bool.optional,
@@ -435,7 +436,7 @@ return /******/ (function(modules) { // webpackBootstrap
435436
Object.defineProperty(exports, "__esModule", {
436437
value: true
437438
});
438-
exports["default"] = "https://github.com/formly-js/angular-formly/blob/" + ("8.3.0") + "/other/ERRORS_AND_WARNINGS.md#";
439+
exports["default"] = "https://github.com/formly-js/angular-formly/blob/" + ("8.4.0") + "/other/ERRORS_AND_WARNINGS.md#";
439440
module.exports = exports["default"];
440441

441442
/***/ },
@@ -564,6 +565,7 @@ return /******/ (function(modules) { // webpackBootstrap
564565
fieldTransform: [],
565566
ngModelAttrsManipulatorPreferUnbound: false,
566567
removeChromeAutoComplete: false,
568+
parseKeyArrays: false,
567569
defaultHideDirective: 'ng-if',
568570
getFieldId: null
569571
},
@@ -1249,7 +1251,7 @@ return /******/ (function(modules) { // webpackBootstrap
12491251

12501252
// @ngInject
12511253
function FormlyFieldController($scope, $timeout, $parse, $controller, formlyValidationMessages) {
1252-
/* eslint max-statements:[2, 34] */
1254+
/* eslint max-statements:[2, 37] */
12531255
if ($scope.options.fieldGroup) {
12541256
setupFieldGroup();
12551257
return;
@@ -1324,6 +1326,25 @@ return /******/ (function(modules) { // webpackBootstrap
13241326
return _angularFix2['default'].isNumber(key) || !formlyUtil.containsSelector(key);
13251327
}
13261328

1329+
function keyContainsArrays(key) {
1330+
return (/\[\d{1,}\]/.test(key)
1331+
);
1332+
}
1333+
1334+
function deepAssign(obj, prop, value) {
1335+
if (_angularFix2['default'].isString(prop)) {
1336+
prop = prop.replace(/\[(\w+)\]/g, '.$1').split('.');
1337+
}
1338+
1339+
if (prop.length > 1) {
1340+
var e = prop.shift();
1341+
obj[e] = obj[e] || isNaN(prop[0]) ? {} : [];
1342+
deepAssign(obj[e], prop, value);
1343+
} else {
1344+
obj[prop[0]] = value;
1345+
}
1346+
}
1347+
13271348
function parseSet(key, model, newVal) {
13281349
// If either of these are null/undefined then just return undefined
13291350
if (!key && key !== 0 || !model) {
@@ -1333,6 +1354,8 @@ return /******/ (function(modules) { // webpackBootstrap
13331354
if (shouldNotUseParseKey(key)) {
13341355
// TODO: Fix this so we can get several levels instead of just one with properties that are numeric
13351356
model[key] = newVal;
1357+
} else if (formlyConfig.extras.parseKeyArrays && keyContainsArrays(key)) {
1358+
deepAssign($scope.model, key, newVal);
13361359
} else {
13371360
var setter = $parse($scope.options.key).assign;
13381361
if (setter) {

dist/formly.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formly.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-formly",
3-
"version": "8.3.0",
3+
"version": "8.4.0",
44
"author": "Astrism <[email protected]>",
55
"contributors": [
66
"Astrism <[email protected]>",

src/directives/formly-field.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
3535

3636
// @ngInject
3737
function FormlyFieldController($scope, $timeout, $parse, $controller, formlyValidationMessages) {
38-
/* eslint max-statements:[2, 34] */
38+
/* eslint max-statements:[2, 37] */
3939
if ($scope.options.fieldGroup) {
4040
setupFieldGroup()
4141
return
@@ -109,6 +109,24 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
109109
return angular.isNumber(key) || !formlyUtil.containsSelector(key)
110110
}
111111

112+
function keyContainsArrays(key) {
113+
return /\[\d{1,}\]/.test(key)
114+
}
115+
116+
function deepAssign(obj, prop, value) {
117+
if (angular.isString(prop)) {
118+
prop = prop.replace(/\[(\w+)\]/g, '.$1').split('.')
119+
}
120+
121+
if (prop.length > 1) {
122+
const e = prop.shift()
123+
obj[e] = obj[e] || (isNaN(prop[0])) ? {} : []
124+
deepAssign(obj[e], prop, value)
125+
} else {
126+
obj[prop[0]] = value
127+
}
128+
}
129+
112130
function parseSet(key, model, newVal) {
113131
// If either of these are null/undefined then just return undefined
114132
if ((!key && key !== 0) || !model) {
@@ -118,6 +136,8 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
118136
if (shouldNotUseParseKey(key)) {
119137
// TODO: Fix this so we can get several levels instead of just one with properties that are numeric
120138
model[key] = newVal
139+
} else if (formlyConfig.extras.parseKeyArrays && keyContainsArrays(key)) {
140+
deepAssign($scope.model, key, newVal)
121141
} else {
122142
const setter = $parse($scope.options.key).assign
123143
if (setter) {

src/directives/formly-field.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,20 @@ describe('formly-field', function() {
566566
expect(scope.model[key]).to.eq(defaultValue)
567567
})
568568

569+
it('should handle arrays properly when formlyConfig.extras.parseKeyArrays is set', () => {
570+
const key = 'foo[0]'
571+
const defaultValue = 'bar'
572+
573+
formlyConfig.extras.parseKeyArrays = true
574+
scope.fields = [
575+
{template: input, key, defaultValue},
576+
]
577+
scope.model = {}
578+
579+
compileAndDigest()
580+
expect(scope.model.foo).to.be.instanceof(Array)
581+
})
582+
569583
it('should get and set values when key is alpha numeric with alpha first', () => {
570584
const key = 'A1'
571585
const defaultValue = 'bar'

src/providers/formlyApiCheck.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const formOptionsApi = apiCheck.shape({
166166
resetModel: apiCheck.func.optional,
167167
updateInitialValue: apiCheck.func.optional,
168168
removeChromeAutoComplete: apiCheck.bool.optional,
169+
parseKeyArrays: apiCheck.bool.optional,
169170
templateManipulators: templateManipulators.optional,
170171
manualModelWatcher: apiCheck.oneOfType([apiCheck.bool, apiCheck.func]).optional,
171172
watchAllExpressions: apiCheck.bool.optional,

src/providers/formlyConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
2828
fieldTransform: [],
2929
ngModelAttrsManipulatorPreferUnbound: false,
3030
removeChromeAutoComplete: false,
31+
parseKeyArrays: false,
3132
defaultHideDirective: 'ng-if',
3233
getFieldId: null,
3334
},

0 commit comments

Comments
 (0)