@stemy/ngx-dynamic-form 10.2.25 → 10.2.26

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.
@@ -527,28 +527,55 @@
527
527
  _this.notifyCallback = notifyCallback;
528
528
  return _this;
529
529
  }
530
+ FormSubject.prototype.handleNotifiedValue = function (controlModel, control, val) {
531
+ var _this = this;
532
+ val.then(function (v) { return _this.next(v); });
533
+ };
530
534
  FormSubject.prototype.notify = function (controlModel, control) {
531
- return __awaiter(this, void 0, void 0, function () {
532
- var value;
533
- return __generator(this, function (_a) {
534
- switch (_a.label) {
535
- case 0:
536
- value = this.notifyCallback(controlModel, control);
537
- if (!(value instanceof Promise)) return [3 /*break*/, 2];
538
- return [4 /*yield*/, value];
539
- case 1:
540
- value = _a.sent();
541
- _a.label = 2;
542
- case 2:
543
- this.next(value);
544
- return [2 /*return*/];
545
- }
546
- });
547
- });
535
+ var path = controlModel;
536
+ while (path && isNaN(path.index)) {
537
+ path = path.parent;
538
+ }
539
+ var value = this.notifyCallback(controlModel, control, path === null || path === void 0 ? void 0 : path.index);
540
+ if (!(value instanceof Promise)) {
541
+ value = Promise.resolve(value);
542
+ }
543
+ this.handleNotifiedValue(controlModel, control, value);
548
544
  };
549
545
  return FormSubject;
550
546
  }(rxjs.Subject));
551
547
 
548
+ var FormSelectSubject = /** @class */ (function (_super) {
549
+ __extends(FormSelectSubject, _super);
550
+ function FormSelectSubject() {
551
+ return _super !== null && _super.apply(this, arguments) || this;
552
+ }
553
+ FormSelectSubject.prototype.handleNotifiedValue = function (controlModel, control, val) {
554
+ var _this = this;
555
+ val.then(function (options) {
556
+ var _a, _b;
557
+ _this.next(options);
558
+ var currentVal = control.value;
559
+ if (controlModel.multiple) {
560
+ var correctVal = (currentVal || []).filter(function (t) { return options.findIndex(function (o) { return o.value == t; }) >= 0; });
561
+ if (correctVal.length !== (currentVal === null || currentVal === void 0 ? void 0 : currentVal.length)) {
562
+ control.setValue(correctVal, { onlySelf: true, emitEvent: false });
563
+ }
564
+ return;
565
+ }
566
+ var option = options.find(function (t) { return t.value == currentVal; });
567
+ if (!option) {
568
+ control.setValue((_b = (_a = options[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null, { onlySelf: true, emitEvent: false });
569
+ }
570
+ });
571
+ };
572
+ return FormSelectSubject;
573
+ }(FormSubject));
574
+
575
+ function isStringWithVal(val) {
576
+ return typeof val == "string" && val.length > 0;
577
+ }
578
+
552
579
  var DynamicFormArrayModel = /** @class */ (function (_super) {
553
580
  __extends(DynamicFormArrayModel, _super);
554
581
  function DynamicFormArrayModel(config, layout) {
@@ -794,7 +821,8 @@
794
821
  };
795
822
  DynamicFormService.prototype.getFormControlModel = function (property, schema) {
796
823
  var _a, _b;
797
- if (Array.isArray(property.enum) || ngxUtils.ObjectUtils.isString(property.optionsPath)) {
824
+ var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
825
+ if (Array.isArray($enum) || isStringWithVal(property.optionsPath) || isStringWithVal(property.endpoint)) {
798
826
  return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
799
827
  }
800
828
  switch (property.type) {
@@ -806,15 +834,10 @@
806
834
  return new core.DynamicTextAreaModel(this.getFormTextareaConfig(property, schema));
807
835
  case "boolean":
808
836
  return new core.DynamicCheckboxModel(this.getFormCheckboxConfig(property, schema));
809
- case "list":
810
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
811
837
  case "array":
812
- if (((_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref) || property.$ref) {
838
+ if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.$ref) || property.$ref) {
813
839
  return new DynamicFormArrayModel(this.getFormArrayConfig(property, schema));
814
840
  }
815
- else if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.enum) || property.enum) {
816
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
817
- }
818
841
  else {
819
842
  return new core.DynamicInputModel(this.getFormInputConfig(property, schema));
820
843
  }
@@ -946,8 +969,17 @@
946
969
  var _this = this;
947
970
  var _a;
948
971
  var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
949
- if (property.optionsPath) {
950
- return new FormSubject(function (formModel, control) {
972
+ if (Array.isArray($enum)) {
973
+ return new FormSelectSubject(function () {
974
+ var options = $enum.map(function (value) {
975
+ var label = property.translatable ? property.id + "." + value : value;
976
+ return { value: value, label: label };
977
+ });
978
+ return _this.translateOptions(options);
979
+ });
980
+ }
981
+ if (isStringWithVal(property.optionsPath)) {
982
+ return new FormSelectSubject(function (formModel, control, index) {
951
983
  var path = property.optionsPath;
952
984
  var target = control;
953
985
  if (path.startsWith("$root")) {
@@ -962,21 +994,12 @@
962
994
  target = target.parent;
963
995
  }
964
996
  }
965
- var value = ngxUtils.ObjectUtils.getValue(target.value, path);
997
+ var value = ngxUtils.ObjectUtils.getValue(target.value, path.replace(/\$ix/gi, index));
966
998
  var options = (!ngxUtils.ObjectUtils.isArray(value) ? [] : value).map(function (value) { return ({ value: value, label: value }); });
967
999
  return _this.translateOptions(options);
968
1000
  });
969
1001
  }
970
- if (ngxUtils.ObjectUtils.isArray($enum)) {
971
- return new FormSubject(function () {
972
- var options = $enum.map(function (value) {
973
- var label = property.translatable ? property.id + "." + value : value;
974
- return { value: value, label: label };
975
- });
976
- return _this.translateOptions(options);
977
- });
978
- }
979
- return new FormSubject(function () { return __awaiter(_this, void 0, void 0, function () {
1002
+ return new FormSelectSubject(function () { return __awaiter(_this, void 0, void 0, function () {
980
1003
  var options;
981
1004
  return __generator(this, function (_c) {
982
1005
  switch (_c.label) {
@@ -1520,6 +1543,7 @@
1520
1543
  exports.FormInput = FormInput;
1521
1544
  exports.FormModel = FormModel;
1522
1545
  exports.FormSelect = FormSelect;
1546
+ exports.FormSelectSubject = FormSelectSubject;
1523
1547
  exports.FormSerializable = FormSerializable;
1524
1548
  exports.FormStatic = FormStatic;
1525
1549
  exports.FormSubject = FormSubject;
@@ -1534,17 +1558,17 @@
1534
1558
  exports.getFormControl = getFormControl;
1535
1559
  exports.getFormFieldSets = getFormFieldSets;
1536
1560
  exports.getFormSerializer = getFormSerializer;
1561
+ exports.validateItemsMaxLength = validateItemsMaxLength;
1562
+ exports.validateItemsMaxValue = validateItemsMaxValue;
1563
+ exports.validateItemsMinLength = validateItemsMinLength;
1564
+ exports.validateItemsMinValue = validateItemsMinValue;
1537
1565
  exports.validateJSON = validateJSON;
1538
1566
  exports.validatePhone = validatePhone;
1539
1567
  exports.validateRequiredTranslation = validateRequiredTranslation;
1540
- exports.ɵa = validateItemsMinLength;
1541
- exports.ɵb = validateItemsMaxLength;
1542
- exports.ɵc = validateItemsMinValue;
1543
- exports.ɵd = validateItemsMaxValue;
1544
- exports.ɵe = components;
1545
- exports.ɵf = directives;
1546
- exports.ɵg = pipes;
1547
- exports.ɵh = DynamicFormValidationService;
1568
+ exports.ɵa = components;
1569
+ exports.ɵb = directives;
1570
+ exports.ɵc = pipes;
1571
+ exports.ɵd = DynamicFormValidationService;
1548
1572
 
1549
1573
  Object.defineProperty(exports, '__esModule', { value: true });
1550
1574