@stemy/ngx-dynamic-form 19.9.17 → 19.9.19

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, Inject, Injectable, untracked, input, Renderer2, ElementRef, computed, signal, effect, HostBinding, Directive, Input, Pipe, Type, Component, Injector, output, ChangeDetectionStrategy, ViewEncapsulation, viewChild, makeEnvironmentProviders, NgModule } from '@angular/core';
2
+ import { InjectionToken, inject, Inject, Injectable, untracked, input, Renderer2, ElementRef, computed, signal, effect, HostBinding, Directive, Input, Optional, Pipe, Type, Component, Injector, output, ChangeDetectionStrategy, ViewEncapsulation, viewChild, makeEnvironmentProviders, NgModule } from '@angular/core';
3
3
  import * as i2 from '@stemy/ngx-utils';
4
4
  import { cachedFactory, ReflectUtils, ObjectUtils, LANGUAGE_SERVICE, ForbiddenZone, ArrayUtils, API_SERVICE, StringUtils, AsyncMethodBase, EventsService, NgxUtilsModule } from '@stemy/ngx-utils';
5
5
  import { of, merge, Observable, firstValueFrom, BehaviorSubject, combineLatestWith, switchMap, distinctUntilChanged, first, Subject, map, filter } from 'rxjs';
@@ -769,11 +769,13 @@ class DynamicFormBuilderService {
769
769
  }
770
770
  createFormSelect(key, data, parent, options) {
771
771
  data = data || {};
772
+ const multiple = data.multiple === true;
773
+ data.defaultValue = data.defaultValue ?? (multiple ? [] : null);
772
774
  const type = `${data.type || "select"}`;
773
775
  const fieldType = type === "radio" ? type : (data.strict === false ? "chips" : "select");
774
776
  const field = this.createFormField(key, fieldType, data, {
775
777
  type,
776
- multiple: data.multiple === true,
778
+ multiple,
777
779
  strict: data.strict !== false,
778
780
  allowEmpty: data.allowEmpty === true,
779
781
  groupBy: data.groupBy,
@@ -933,8 +935,15 @@ class DynamicFormBuilderService {
933
935
  }));
934
936
  const control = field.formControl;
935
937
  const multiple = field.props.multiple;
936
- field.defaultValue = multiple ? [] : options[0]?.value ?? null;
937
- if (multiple || options.length === 0 || options.findIndex(o => o.value === control.value) >= 0)
938
+ if (multiple) {
939
+ // Handle if current control value is not an array
940
+ const value = Array.isArray(control.value)
941
+ ? control.value
942
+ : String(control.value || "").split(",");
943
+ control.setValue(value);
944
+ return options;
945
+ }
946
+ if (options.length === 0 || options.findIndex(o => o.value === control.value) >= 0)
938
947
  return options;
939
948
  control.setValue(field.defaultValue);
940
949
  return options;
@@ -1378,8 +1387,9 @@ class DynamicFormSchemaService {
1378
1387
  const endpoint = entries.reduce((res, [key, control]) => {
1379
1388
  return this.replaceOptionsEndpoint(res, key, control.value);
1380
1389
  }, `${property.endpoint}`);
1390
+ const cache = property.cache ?? new Date(Date.now() + 20_000);
1381
1391
  const data = await this.api.list(endpoint, this.api.makeListParams(1, -1), {
1382
- cache: this.api.cached(property.cache),
1392
+ cache: this.api.cached(cache),
1383
1393
  read: String(property.responseProperty || "")
1384
1394
  });
1385
1395
  const items = ObjectUtils.isArray(data)
@@ -1831,6 +1841,8 @@ class DynamicFormTemplateDirective {
1831
1841
  this.templates.remove(...this.setting);
1832
1842
  }
1833
1843
  selectType() {
1844
+ if (!this.templates)
1845
+ return null;
1834
1846
  const inputs = Object.keys(this);
1835
1847
  for (const input of inputs) {
1836
1848
  const value = this[input];
@@ -1840,7 +1852,7 @@ class DynamicFormTemplateDirective {
1840
1852
  }
1841
1853
  return null;
1842
1854
  }
1843
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormTemplateDirective, deps: [{ token: DynamicFormTemplateService }, { token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
1855
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormTemplateDirective, deps: [{ token: DynamicFormTemplateService, optional: true }, { token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
1844
1856
  static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.19", type: DynamicFormTemplateDirective, isStandalone: false, selector: "ng-template[control],\n ng-template[label],\n ng-template[input],\n ng-template[prefix],\n ng-template[suffix],\n ng-template[setPrefix],\n ng-template[setSuffix]", inputs: { control: "control", label: "label", input: "input", prefix: "prefix", suffix: "suffix", setPrefix: "setPrefix", setSuffix: "setSuffix" }, usesOnChanges: true, ngImport: i0 });
1845
1857
  }
1846
1858
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormTemplateDirective, decorators: [{
@@ -1855,7 +1867,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImpo
1855
1867
  ng-template[setPrefix],
1856
1868
  ng-template[setSuffix]`
1857
1869
  }]
1858
- }], ctorParameters: () => [{ type: DynamicFormTemplateService }, { type: i0.TemplateRef }], propDecorators: { control: [{
1870
+ }], ctorParameters: () => [{ type: DynamicFormTemplateService, decorators: [{
1871
+ type: Optional
1872
+ }] }, { type: i0.TemplateRef }], propDecorators: { control: [{
1859
1873
  type: Input
1860
1874
  }], label: [{
1861
1875
  type: Input