@ngx-formly/core 5.10.28 → 5.10.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/bundles/ngx-formly-core-json-schema.umd.js +6 -2
  2. package/bundles/ngx-formly-core-json-schema.umd.js.map +1 -1
  3. package/bundles/ngx-formly-core-json-schema.umd.min.js +1 -1
  4. package/bundles/ngx-formly-core-json-schema.umd.min.js.map +1 -1
  5. package/bundles/ngx-formly-core.umd.js +105 -147
  6. package/bundles/ngx-formly-core.umd.js.map +1 -1
  7. package/bundles/ngx-formly-core.umd.min.js +1 -1
  8. package/bundles/ngx-formly-core.umd.min.js.map +1 -1
  9. package/esm2015/json-schema/formly-json-schema.service.js +8 -4
  10. package/esm2015/lib/components/formly.attributes.js +33 -24
  11. package/esm2015/lib/core.js +2 -2
  12. package/esm2015/lib/extensions/core/core.js +2 -1
  13. package/esm2015/lib/extensions/field-expression/field-expression.js +3 -6
  14. package/esm2015/lib/extensions/field-form/field-form.js +23 -55
  15. package/esm2015/lib/extensions/field-form/utils.js +9 -3
  16. package/esm2015/lib/services/formly.form.builder.js +3 -3
  17. package/esm2015/lib/templates/formly.validation-message.js +14 -3
  18. package/esm2015/lib/utils.js +21 -42
  19. package/esm2015/ngx-formly-core.js +2 -2
  20. package/esm2015/public_api.js +2 -2
  21. package/esm5/json-schema/formly-json-schema.service.js +8 -4
  22. package/esm5/lib/components/formly.attributes.js +32 -21
  23. package/esm5/lib/core.js +2 -2
  24. package/esm5/lib/extensions/core/core.js +2 -1
  25. package/esm5/lib/extensions/field-expression/field-expression.js +3 -6
  26. package/esm5/lib/extensions/field-form/field-form.js +25 -55
  27. package/esm5/lib/extensions/field-form/utils.js +10 -3
  28. package/esm5/lib/services/formly.form.builder.js +3 -3
  29. package/esm5/lib/templates/formly.validation-message.js +15 -3
  30. package/esm5/lib/utils.js +24 -59
  31. package/esm5/ngx-formly-core.js +2 -2
  32. package/esm5/public_api.js +2 -2
  33. package/fesm2015/ngx-formly-core-json-schema.js +7 -3
  34. package/fesm2015/ngx-formly-core-json-schema.js.map +1 -1
  35. package/fesm2015/ngx-formly-core.js +98 -128
  36. package/fesm2015/ngx-formly-core.js.map +1 -1
  37. package/fesm5/ngx-formly-core-json-schema.js +7 -3
  38. package/fesm5/ngx-formly-core-json-schema.js.map +1 -1
  39. package/fesm5/ngx-formly-core.js +104 -142
  40. package/fesm5/ngx-formly-core.js.map +1 -1
  41. package/json-schema/ngx-formly-core-json-schema.metadata.json +1 -1
  42. package/lib/core.d.ts +1 -1
  43. package/lib/extensions/field-form/utils.d.ts +1 -1
  44. package/lib/utils.d.ts +1 -2
  45. package/ngx-formly-core.metadata.json +1 -1
  46. package/package.json +1 -1
@@ -102,6 +102,20 @@
102
102
  * @fileoverview added by tsickle
103
103
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
104
104
  */
105
+ /**
106
+ * @param {?} form
107
+ * @param {?} callback
108
+ * @return {?}
109
+ */
110
+ function disableTreeValidityCall(form, callback) {
111
+ /** @type {?} */
112
+ var _updateTreeValidity = form._updateTreeValidity.bind(form);
113
+ form._updateTreeValidity = ( /**
114
+ * @return {?}
115
+ */function () { });
116
+ callback();
117
+ form._updateTreeValidity = _updateTreeValidity;
118
+ }
105
119
  /**
106
120
  * @param {?} formId
107
121
  * @param {?} field
@@ -113,8 +127,12 @@
113
127
  return field.id;
114
128
  /** @type {?} */
115
129
  var type = field.type;
116
- if (!type && field.template)
130
+ if (!type && field.template) {
117
131
  type = 'template';
132
+ }
133
+ if (isFunction(type)) {
134
+ type = (( /** @type {?} */(type))).prototype.constructor.name;
135
+ }
118
136
  return [formId, type, field.key, index].join('_');
119
137
  }
120
138
  /**
@@ -196,50 +214,12 @@
196
214
  }
197
215
  model[paths[paths.length - 1]] = clone(value);
198
216
  }
199
- /**
200
- * @param {?} field
201
- * @return {?}
202
- */
203
- function getFieldInitialValue(field) {
204
- var e_1, _a;
205
- /** @type {?} */
206
- var value = field.options['_initialModel'];
207
- /** @type {?} */
208
- var paths = getKeyPath(field);
209
- while (field.parent) {
210
- field = field.parent;
211
- paths = __spread(getKeyPath(field), paths);
212
- }
213
- try {
214
- for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
215
- var path = paths_1_1.value;
216
- if (!value) {
217
- return undefined;
218
- }
219
- value = value[path];
220
- }
221
- }
222
- catch (e_1_1) {
223
- e_1 = { error: e_1_1 };
224
- }
225
- finally {
226
- try {
227
- if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return))
228
- _a.call(paths_1);
229
- }
230
- finally {
231
- if (e_1)
232
- throw e_1.error;
233
- }
234
- }
235
- return value;
236
- }
237
217
  /**
238
218
  * @param {?} field
239
219
  * @return {?}
240
220
  */
241
221
  function getFieldValue(field) {
242
- var e_2, _a;
222
+ var e_1, _a;
243
223
  /** @type {?} */
244
224
  var model = field.parent.model;
245
225
  try {
@@ -251,8 +231,8 @@
251
231
  model = model[path];
252
232
  }
253
233
  }
254
- catch (e_2_1) {
255
- e_2 = { error: e_2_1 };
234
+ catch (e_1_1) {
235
+ e_1 = { error: e_1_1 };
256
236
  }
257
237
  finally {
258
238
  try {
@@ -260,8 +240,8 @@
260
240
  _a.call(_b);
261
241
  }
262
242
  finally {
263
- if (e_2)
264
- throw e_2.error;
243
+ if (e_1)
244
+ throw e_1.error;
265
245
  }
266
246
  }
267
247
  return model;
@@ -459,27 +439,6 @@
459
439
  * @return {?}
460
440
  */function () { return fns.splice(fns.indexOf(setFn), 1); });
461
441
  }
462
- /**
463
- * @param {?} form
464
- * @param {?} action
465
- * @return {?}
466
- */
467
- function reduceFormUpdateValidityCalls(form, action) {
468
- /** @type {?} */
469
- var updateValidity = form._updateTreeValidity.bind(form);
470
- /** @type {?} */
471
- var updateValidityArgs = { called: false, emitEvent: false };
472
- form._updateTreeValidity = ( /**
473
- * @param {?=} __0
474
- * @return {?}
475
- */function (_a) {
476
- var emitEvent = (_a === void 0 ? { emitEvent: true } : _a).emitEvent;
477
- return updateValidityArgs = { called: true, emitEvent: emitEvent || updateValidityArgs.emitEvent };
478
- });
479
- action();
480
- updateValidityArgs.called && updateValidity({ emitEvent: updateValidityArgs.emitEvent });
481
- form._updateTreeValidity = updateValidity;
482
- }
483
442
 
484
443
  /**
485
444
  * @fileoverview added by tsickle
@@ -863,7 +822,7 @@
863
822
  }
864
823
  /** @type {?} */
865
824
  var field = { fieldGroup: fieldGroup, model: model, formControl: formControl, options: this._setOptions(options) };
866
- reduceFormUpdateValidityCalls(formControl, ( /**
825
+ disableTreeValidityCall(formControl, ( /**
867
826
  * @return {?}
868
827
  */function () { return _this._buildForm(field); }));
869
828
  field.options._checkField(field, true);
@@ -1139,15 +1098,24 @@
1139
1098
  }
1140
1099
  /**
1141
1100
  * @param {?} c
1101
+ * @param {?=} onlySelf
1142
1102
  * @return {?}
1143
1103
  */
1144
- function updateValidity(c) {
1104
+ function updateValidity(c, onlySelf) {
1105
+ if (onlySelf === void 0) {
1106
+ onlySelf = false;
1107
+ }
1145
1108
  /** @type {?} */
1146
1109
  var status = c.status;
1147
- c.updateValueAndValidity({ emitEvent: false });
1110
+ /** @type {?} */
1111
+ var value = c.value;
1112
+ c.updateValueAndValidity({ emitEvent: false, onlySelf: onlySelf });
1148
1113
  if (status !== c.status) {
1149
1114
  (( /** @type {?} */(c.statusChanges))).emit(c.status);
1150
1115
  }
1116
+ if (value !== c.value) {
1117
+ (( /** @type {?} */(c.valueChanges))).emit(c.value);
1118
+ }
1151
1119
  }
1152
1120
  /**
1153
1121
  * @param {?} form
@@ -1947,16 +1915,11 @@
1947
1915
  */
1948
1916
  var FormlyAttributes = /** @class */ (function () {
1949
1917
  function FormlyAttributes(renderer, elementRef, _document) {
1918
+ var _this = this;
1950
1919
  this.renderer = renderer;
1951
1920
  this.elementRef = elementRef;
1952
1921
  this.uiAttributesCache = {};
1953
- this.uiAttributes = __spread(FORMLY_VALIDATORS, [
1954
- 'tabindex',
1955
- 'placeholder',
1956
- 'readonly',
1957
- 'disabled',
1958
- 'step',
1959
- ]);
1922
+ this.uiAttributes = null;
1960
1923
  /**
1961
1924
  * HostBinding doesn't register listeners conditionally which may produce some perf issues.
1962
1925
  *
@@ -1964,12 +1927,23 @@
1964
1927
  */
1965
1928
  this.uiEvents = {
1966
1929
  listeners: [],
1967
- events: [
1968
- 'click',
1969
- 'keyup',
1970
- 'keydown',
1971
- 'keypress',
1972
- ],
1930
+ events: ['click', 'keyup', 'keydown', 'keypress', 'focus', 'blur', 'change'],
1931
+ callback: ( /**
1932
+ * @param {?} eventName
1933
+ * @param {?} $event
1934
+ * @return {?}
1935
+ */function (eventName, $event) {
1936
+ switch (eventName) {
1937
+ case 'focus':
1938
+ return _this.onFocus($event);
1939
+ case 'blur':
1940
+ return _this.onBlur($event);
1941
+ case 'change':
1942
+ return _this.onChange($event);
1943
+ default:
1944
+ return _this.to[eventName](_this.field, $event);
1945
+ }
1946
+ }),
1973
1947
  };
1974
1948
  this.document = _document;
1975
1949
  }
@@ -2008,11 +1982,11 @@
2008
1982
  * @param {?} eventName
2009
1983
  * @return {?}
2010
1984
  */function (eventName) {
2011
- if (_this.to && _this.to[eventName]) {
1985
+ if ((_this.to && _this.to[eventName]) || ['focus', 'blur', 'change'].indexOf(eventName) !== -1) {
2012
1986
  _this.uiEvents.listeners.push(_this.renderer.listen(_this.elementRef.nativeElement, eventName, ( /**
2013
1987
  * @param {?} e
2014
1988
  * @return {?}
2015
- */function (e) { return _this.to[eventName](_this.field, e); })));
1989
+ */function (e) { return _this.uiEvents.callback(eventName, e); })));
2016
1990
  }
2017
1991
  }));
2018
1992
  if (this.to && this.to.attributes) {
@@ -2084,6 +2058,14 @@
2084
2058
  */
2085
2059
  function () {
2086
2060
  var _this = this;
2061
+ if (!this.uiAttributes) {
2062
+ /** @type {?} */
2063
+ var element_1 = ( /** @type {?} */(this.elementRef.nativeElement));
2064
+ this.uiAttributes = __spread(FORMLY_VALIDATORS, ['tabindex', 'placeholder', 'readonly', 'disabled', 'step']).filter(( /**
2065
+ * @param {?} attr
2066
+ * @return {?}
2067
+ */function (attr) { return !element_1.hasAttribute || !element_1.hasAttribute(attr); }));
2068
+ }
2087
2069
  this.uiAttributes.forEach(( /**
2088
2070
  * @param {?} attr
2089
2071
  * @return {?}
@@ -2260,11 +2242,6 @@
2260
2242
  FormlyAttributes.decorators = [
2261
2243
  { type: i0.Directive, args: [{
2262
2244
  selector: '[formlyAttributes]',
2263
- host: {
2264
- '(focus)': 'onFocus($event)',
2265
- '(blur)': 'onBlur($event)',
2266
- '(change)': 'onChange($event)',
2267
- },
2268
2245
  },] }
2269
2246
  ];
2270
2247
  /** @nocollapse */
@@ -2570,9 +2547,19 @@
2570
2547
  */
2571
2548
  function () {
2572
2549
  var _this = this;
2573
- this.errorMessage$ = this.field.formControl.statusChanges.pipe(operators.startWith(null), operators.switchMap(( /**
2574
- * @return {?}
2575
- */function () {
2550
+ this.errorMessage$ = rxjs.merge(this.field.formControl.statusChanges, (!this.field.options
2551
+ ? rxjs.of(null)
2552
+ : this.field.options.fieldChanges.pipe(operators.filter(( /**
2553
+ * @param {?} __0
2554
+ * @return {?}
2555
+ */function (_a) {
2556
+ var field = _a.field, type = _a.type, property = _a.property;
2557
+ return (field === _this.field)
2558
+ && (type === 'expressionChanges')
2559
+ && (property.indexOf('validation') !== -1);
2560
+ }))))).pipe(operators.startWith(null), operators.switchMap(( /**
2561
+ * @return {?}
2562
+ */function () {
2576
2563
  return rxjs.isObservable(_this.errorMessage)
2577
2564
  ? _this.errorMessage
2578
2565
  : rxjs.of(_this.errorMessage);
@@ -2747,9 +2734,7 @@
2747
2734
  */function (f, ignoreCache) {
2748
2735
  if (!checkLocked) {
2749
2736
  checkLocked = true;
2750
- reduceFormUpdateValidityCalls(f.formControl, ( /**
2751
- * @return {?}
2752
- */function () { return _this.checkField(f, ignoreCache); }));
2737
+ _this.checkField(f, ignoreCache);
2753
2738
  checkLocked = false;
2754
2739
  }
2755
2740
  });
@@ -3527,22 +3512,7 @@
3527
3512
  if (field.parent) {
3528
3513
  return;
3529
3514
  }
3530
- /** @type {?} */
3531
- var fieldsToUpdate = this.setValidators(field);
3532
- if (fieldsToUpdate.length === 0) {
3533
- return;
3534
- }
3535
- if (fieldsToUpdate.length === 1) {
3536
- /** @type {?} */
3537
- var control = fieldsToUpdate[0].formControl;
3538
- while (control) {
3539
- (( /** @type {?} */(control)))._updateTreeValidity({ onlySelf: true });
3540
- control = control.parent;
3541
- }
3542
- }
3543
- else {
3544
- (( /** @type {?} */(field.formControl)))._updateTreeValidity();
3545
- }
3515
+ this.setValidators(field);
3546
3516
  };
3547
3517
  /**
3548
3518
  * @private
@@ -3583,39 +3553,40 @@
3583
3553
  /**
3584
3554
  * @private
3585
3555
  * @param {?} field
3556
+ * @param {?=} disabled
3586
3557
  * @return {?}
3587
3558
  */
3588
3559
  FieldFormExtension.prototype.setValidators = /**
3589
3560
  * @private
3590
3561
  * @param {?} field
3562
+ * @param {?=} disabled
3591
3563
  * @return {?}
3592
3564
  */
3593
- function (field) {
3565
+ function (field, disabled) {
3594
3566
  var _this = this;
3567
+ if (disabled === void 0) {
3568
+ disabled = false;
3569
+ }
3595
3570
  /** @type {?} */
3596
- var updateValidity$$1 = false;
3571
+ var markForCheck = false;
3572
+ if (disabled === false && field.key && field.templateOptions && field.templateOptions.disabled) {
3573
+ disabled = true;
3574
+ }
3575
+ (field.fieldGroup || []).forEach(( /**
3576
+ * @param {?} f
3577
+ * @return {?}
3578
+ */function (f) { return _this.setValidators(f, disabled) && (markForCheck = true); }));
3597
3579
  if (field.key || !field.parent || (!field.key && !field.fieldGroup)) {
3598
3580
  var c_1 = field.formControl;
3599
- /** @type {?} */
3600
- var disabled = field.templateOptions ? field.templateOptions.disabled : false;
3601
- if (field.key && c_1) {
3581
+ field.templateOptions = field.templateOptions || {};
3582
+ if (field.key && c_1 && c_1 instanceof forms.FormControl) {
3602
3583
  if (disabled && c_1.enabled) {
3603
3584
  c_1.disable({ emitEvent: false, onlySelf: true });
3604
- if (!c_1.parent) {
3605
- updateValidity(c_1);
3606
- }
3607
- else {
3608
- updateValidity$$1 = true;
3609
- }
3585
+ markForCheck = true;
3610
3586
  }
3611
3587
  if (!disabled && c_1.disabled) {
3612
3588
  c_1.enable({ emitEvent: false, onlySelf: true });
3613
- if (!c_1.parent) {
3614
- updateValidity(c_1);
3615
- }
3616
- else {
3617
- updateValidity$$1 = true;
3618
- }
3589
+ markForCheck = true;
3619
3590
  }
3620
3591
  }
3621
3592
  if (c_1 && (null === c_1.validator || null === c_1.asyncValidator)) {
@@ -3633,27 +3604,13 @@
3633
3604
  var v = forms.Validators.composeAsync(_this.mergeValidators(field, '_asyncValidators'));
3634
3605
  return v ? v(c_1) : rxjs.of(null);
3635
3606
  }));
3636
- if (!c_1.parent) {
3637
- updateValidity(c_1);
3638
- }
3639
- else {
3640
- updateValidity$$1 = true;
3641
- }
3607
+ markForCheck = true;
3642
3608
  }
3643
- }
3644
- /** @type {?} */
3645
- var fieldsToUpdate = updateValidity$$1 ? [field] : [];
3646
- (field.fieldGroup || []).forEach(( /**
3647
- * @param {?} f
3648
- * @return {?}
3649
- */function (f) {
3650
- /** @type {?} */
3651
- var childrenToUpdate = _this.setValidators(f);
3652
- if (!updateValidity$$1) {
3653
- fieldsToUpdate.push.apply(fieldsToUpdate, __spread(childrenToUpdate));
3609
+ if (markForCheck) {
3610
+ updateValidity(c_1, true);
3654
3611
  }
3655
- }));
3656
- return fieldsToUpdate;
3612
+ }
3613
+ return markForCheck;
3657
3614
  };
3658
3615
  /**
3659
3616
  * @private
@@ -3819,6 +3776,7 @@
3819
3776
  id: getFieldId("formly_" + this.formId, field, field['index']),
3820
3777
  hooks: {},
3821
3778
  modelOptions: {},
3779
+ validation: { messages: {} },
3822
3780
  templateOptions: !field.type || !field.key ? {} : {
3823
3781
  label: '',
3824
3782
  placeholder: '',
@@ -4063,7 +4021,7 @@
4063
4021
  exports.FormlyModule = FormlyModule;
4064
4022
  exports.ɵdefineHiddenProp = defineHiddenProp;
4065
4023
  exports.ɵreverseDeepMerge = reverseDeepMerge;
4066
- exports.ɵgetFieldInitialValue = getFieldInitialValue;
4024
+ exports.ɵgetFieldValue = getFieldValue;
4067
4025
  exports.ɵclone = clone;
4068
4026
  exports.ɵwrapProperty = wrapProperty;
4069
4027
  exports.ɵa = defaultFormlyConfig;