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

Commit 589e7dc

Browse files
committed
v7.3.2
2 parents b7d9593 + 027b79e commit 589e7dc

File tree

6 files changed

+174
-35
lines changed

6 files changed

+174
-35
lines changed

dist/formly.js

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* angular-formly JavaScript Library v7.3.1
2+
* angular-formly JavaScript Library v7.3.2
33
*
44
* @license MIT (http://license.angular-formly.com)
55
*
@@ -153,7 +153,7 @@ return /******/ (function(modules) { // webpackBootstrap
153153

154154
ngModule.constant('formlyApiCheck', _providersFormlyApiCheck2['default']);
155155
ngModule.constant('formlyErrorAndWarningsUrlPrefix', _otherDocsBaseUrl2['default']);
156-
ngModule.constant('formlyVersion', ("7.3.1")); // <-- webpack variable
156+
ngModule.constant('formlyVersion', ("7.3.2")); // <-- webpack variable
157157

158158
ngModule.provider('formlyUsability', _providersFormlyUsability2['default']);
159159
ngModule.provider('formlyConfig', _providersFormlyConfig2['default']);
@@ -424,7 +424,7 @@ return /******/ (function(modules) { // webpackBootstrap
424424
Object.defineProperty(exports, "__esModule", {
425425
value: true
426426
});
427-
exports["default"] = "https://github.com/formly-js/angular-formly/blob/" + ("7.3.1") + "/other/ERRORS_AND_WARNINGS.md#";
427+
exports["default"] = "https://github.com/formly-js/angular-formly/blob/" + ("7.3.2") + "/other/ERRORS_AND_WARNINGS.md#";
428428
module.exports = exports["default"];
429429

430430
/***/ },
@@ -1262,9 +1262,41 @@ return /******/ (function(modules) { // webpackBootstrap
12621262
return undefined;
12631263
}
12641264
if (_angularFix2['default'].isDefined(newVal)) {
1265-
$scope.model[$scope.options.key] = newVal;
1265+
parseSet($scope.options.key, $scope.model, newVal);
1266+
}
1267+
return parseGet($scope.options.key, $scope.model);
1268+
}
1269+
1270+
function parseSet(key, model, newVal) {
1271+
// If either of these are null/undefined then just return undefined
1272+
if (!key || !model) {
1273+
return;
1274+
}
1275+
// If we are working with a number then $parse wont work, default back to the old way for now
1276+
if (_angularFix2['default'].isNumber(key)) {
1277+
// TODO: Fix this so we can get several levels instead of just one with properties that are numeric
1278+
model[key] = newVal;
1279+
} else {
1280+
var setter = $parse($scope.options.key).assign;
1281+
if (setter) {
1282+
setter($scope.model, newVal);
1283+
}
1284+
}
1285+
}
1286+
1287+
function parseGet(key, model) {
1288+
// If either of these are null/undefined then just return undefined
1289+
if (!key || !model) {
1290+
return undefined;
1291+
}
1292+
1293+
// If we are working with a number then $parse wont work, default back to the old way for now
1294+
if (_angularFix2['default'].isNumber(key)) {
1295+
// TODO: Fix this so we can get several levels instead of just one with properties that are numeric
1296+
return model[key];
1297+
} else {
1298+
return $parse(key)(model);
12661299
}
1267-
return $scope.model[$scope.options.key];
12681300
}
12691301

12701302
function simplifyLife(options) {
@@ -1294,14 +1326,13 @@ return /******/ (function(modules) { // webpackBootstrap
12941326
}
12951327

12961328
function setDefaultValue() {
1297-
if (_angularFix2['default'].isDefined($scope.options.defaultValue) && !_angularFix2['default'].isDefined($scope.model[$scope.options.key])) {
1298-
var setter = $parse($scope.options.key).assign;
1299-
setter($scope.model, $scope.options.defaultValue);
1329+
if (_angularFix2['default'].isDefined($scope.options.defaultValue) && !_angularFix2['default'].isDefined(parseGet($scope.options.key, $scope.model))) {
1330+
parseSet($scope.options.key, $scope.model, $scope.options.defaultValue);
13001331
}
13011332
}
13021333

13031334
function setInitialValue() {
1304-
$scope.options.initialValue = $scope.model && $scope.model[$scope.options.key];
1335+
$scope.options.initialValue = $scope.model && parseGet($scope.options.key, $scope.model);
13051336
}
13061337

13071338
function mergeFieldOptionsWithTypeDefaults(options, type) {
@@ -1336,7 +1367,7 @@ return /******/ (function(modules) { // webpackBootstrap
13361367
}
13371368

13381369
function resetModel() {
1339-
$scope.model[$scope.options.key] = $scope.options.initialValue;
1370+
parseSet($scope.options.key, $scope.model, $scope.options.initialValue);
13401371
if ($scope.options.formControl) {
13411372
if (_angularFix2['default'].isArray($scope.options.formControl)) {
13421373
_angularFix2['default'].forEach($scope.options.formControl, function (formControl) {
@@ -1350,7 +1381,7 @@ return /******/ (function(modules) { // webpackBootstrap
13501381

13511382
function resetFormControl(formControl, isMultiNgModel) {
13521383
if (!isMultiNgModel) {
1353-
formControl.$setViewValue($scope.model[$scope.options.key]);
1384+
formControl.$setViewValue(parseGet($scope.options.key, $scope.model));
13541385
}
13551386

13561387
formControl.$render();
@@ -1364,7 +1395,7 @@ return /******/ (function(modules) { // webpackBootstrap
13641395
}
13651396

13661397
function updateInitialValue() {
1367-
$scope.options.initialValue = $scope.model[$scope.options.key];
1398+
$scope.options.initialValue = parseGet($scope.options.key, $scope.model);
13681399
}
13691400

13701401
function addValidationMessages(options) {

dist/formly.min.js

Lines changed: 43 additions & 12 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": "7.3.1",
3+
"version": "7.3.2",
44
"author": "Astrism <[email protected]>",
55
"contributors": [
66
"Astrism <[email protected]>",

src/directives/formly-field.js

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,41 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
7777
return undefined
7878
}
7979
if (angular.isDefined(newVal)) {
80-
$scope.model[$scope.options.key] = newVal
80+
parseSet($scope.options.key, $scope.model, newVal)
81+
}
82+
return parseGet($scope.options.key, $scope.model)
83+
}
84+
85+
function parseSet(key, model, newVal) {
86+
// If either of these are null/undefined then just return undefined
87+
if (!key || !model) {
88+
return
89+
}
90+
// If we are working with a number then $parse wont work, default back to the old way for now
91+
if (angular.isNumber(key)) {
92+
// TODO: Fix this so we can get several levels instead of just one with properties that are numeric
93+
model[key] = newVal
94+
} else {
95+
const setter = $parse($scope.options.key).assign
96+
if (setter) {
97+
setter($scope.model, newVal)
98+
}
99+
}
100+
}
101+
102+
function parseGet(key, model) {
103+
// If either of these are null/undefined then just return undefined
104+
if (!key || !model) {
105+
return undefined
106+
}
107+
108+
// If we are working with a number then $parse wont work, default back to the old way for now
109+
if (angular.isNumber(key)) {
110+
// TODO: Fix this so we can get several levels instead of just one with properties that are numeric
111+
return model[key]
112+
} else {
113+
return $parse(key)(model)
81114
}
82-
return $scope.model[$scope.options.key]
83115
}
84116

85117
function simplifyLife(options) {
@@ -109,14 +141,14 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
109141
}
110142

111143
function setDefaultValue() {
112-
if (angular.isDefined($scope.options.defaultValue) && !angular.isDefined($scope.model[$scope.options.key])) {
113-
const setter = $parse($scope.options.key).assign
114-
setter($scope.model, $scope.options.defaultValue)
144+
if (angular.isDefined($scope.options.defaultValue) &&
145+
!angular.isDefined(parseGet($scope.options.key, $scope.model))) {
146+
parseSet($scope.options.key, $scope.model, $scope.options.defaultValue)
115147
}
116148
}
117149

118150
function setInitialValue() {
119-
$scope.options.initialValue = $scope.model && $scope.model[$scope.options.key]
151+
$scope.options.initialValue = $scope.model && parseGet($scope.options.key, $scope.model)
120152
}
121153

122154
function mergeFieldOptionsWithTypeDefaults(options, type) {
@@ -151,7 +183,7 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
151183
}
152184

153185
function resetModel() {
154-
$scope.model[$scope.options.key] = $scope.options.initialValue
186+
parseSet($scope.options.key, $scope.model, $scope.options.initialValue)
155187
if ($scope.options.formControl) {
156188
if (angular.isArray($scope.options.formControl)) {
157189
angular.forEach($scope.options.formControl, function(formControl) {
@@ -165,7 +197,7 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
165197

166198
function resetFormControl(formControl, isMultiNgModel) {
167199
if (!isMultiNgModel) {
168-
formControl.$setViewValue($scope.model[$scope.options.key])
200+
formControl.$setViewValue(parseGet($scope.options.key, $scope.model))
169201
}
170202

171203
formControl.$render()
@@ -179,7 +211,7 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
179211
}
180212

181213
function updateInitialValue() {
182-
$scope.options.initialValue = $scope.model[$scope.options.key]
214+
$scope.options.initialValue = parseGet($scope.options.key, $scope.model)
183215
}
184216

185217
function addValidationMessages(options) {

src/directives/formly-field.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,51 @@ describe('formly-field', function() {
12401240
expect(field.formControl.$dirty).to.be.false
12411241
})
12421242

1243+
it(`should reset the form state with a deep model`, () => {
1244+
const field = getNewField({key: 'foo.bar'})
1245+
scope.fields = [field]
1246+
compileAndDigest()
1247+
1248+
// initial state
1249+
expect(field.formControl.$dirty).to.be.false
1250+
expect(field.formControl.$touched).to.be.false
1251+
1252+
// modification
1253+
scope.model.foo = {
1254+
bar: '~=[,,_,,]:3',
1255+
}
1256+
field.formControl.$setTouched()
1257+
field.formControl.$setDirty()
1258+
scope.$digest()
1259+
1260+
// expect modification
1261+
expect(field.formControl.$dirty).to.be.true
1262+
expect(field.formControl.$touched).to.be.true
1263+
expect(field.formControl.$modelValue).to.eq('~=[,,_,,]:3')
1264+
1265+
// Set new initialValue
1266+
scope.options.updateInitialValue()
1267+
1268+
// Modify again
1269+
scope.model.foo.bar = 'l33t'
1270+
field.formControl.$setTouched()
1271+
field.formControl.$setDirty()
1272+
scope.$digest()
1273+
1274+
// expect modification
1275+
expect(field.formControl.$dirty).to.be.true
1276+
expect(field.formControl.$touched).to.be.true
1277+
expect(field.formControl.$modelValue).to.eq('l33t')
1278+
1279+
// reset state
1280+
scope.options.resetModel()
1281+
1282+
// expect reset
1283+
expect(field.formControl.$modelValue).to.eq('~=[,,_,,]:3')
1284+
expect(field.formControl.$touched).to.be.false
1285+
expect(field.formControl.$dirty).to.be.false
1286+
})
1287+
12431288
it(`should reset the form state for an field with multiple ng-models`, () => {
12441289
const field = {
12451290
key: 'multiNgModel',

0 commit comments

Comments
 (0)