@3kles/kles-material-dynamicforms 14.0.11 → 14.0.13

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.
@@ -1006,6 +1006,7 @@ let KlesFormSelectComponent = class KlesFormSelectComponent extends KlesFieldAbs
1006
1006
  this.viewRef = viewRef;
1007
1007
  this.ref = ref;
1008
1008
  this.isLoading = false;
1009
+ this.openChange$ = new Subject();
1009
1010
  this.compareFn = (o1, o2) => {
1010
1011
  if (this.field.property && o1 && o2) {
1011
1012
  return o1[this.field.property] === o2[this.field.property];
@@ -1016,12 +1017,34 @@ let KlesFormSelectComponent = class KlesFormSelectComponent extends KlesFieldAbs
1016
1017
  ngOnInit() {
1017
1018
  super.ngOnInit();
1018
1019
  if (this.field.lazy) {
1020
+ this.isLoading = true;
1019
1021
  if (this.field.value) {
1020
1022
  this.options$ = new BehaviorSubject(Array.isArray(this.field.value) ? this.field.value : [this.field.value]);
1023
+ this.isLoading = false;
1021
1024
  }
1022
1025
  else {
1023
1026
  this.options$ = new BehaviorSubject([]);
1024
1027
  }
1028
+ this.openChange$
1029
+ .pipe(takeUntil(this._onDestroy), switchMap((isOpen) => {
1030
+ if (isOpen) {
1031
+ if (!(this.field.options instanceof Observable)) {
1032
+ return of(this.field.options);
1033
+ }
1034
+ else {
1035
+ this.isLoading = true;
1036
+ return this.field.options.pipe(take(1));
1037
+ }
1038
+ }
1039
+ else {
1040
+ return of(this.group.controls[this.field.name].value !== undefined ? [this.group.controls[this.field.name].value] : []);
1041
+ }
1042
+ }))
1043
+ .subscribe((options) => {
1044
+ this.options$.next(options);
1045
+ this.isLoading = false;
1046
+ this.ref.markForCheck();
1047
+ });
1025
1048
  }
1026
1049
  else {
1027
1050
  if (!(this.field.options instanceof Observable)) {
@@ -1037,19 +1060,24 @@ let KlesFormSelectComponent = class KlesFormSelectComponent extends KlesFieldAbs
1037
1060
  }
1038
1061
  openChange($event) {
1039
1062
  if (this.field.lazy) {
1040
- if ($event) {
1041
- if (!(this.field.options instanceof Observable)) {
1042
- this.options$.next(this.field.options);
1043
- }
1044
- else {
1045
- this.isLoading = true;
1046
- this.field.options.pipe(take(1)).subscribe(options => {
1047
- this.options$.next(options);
1048
- this.isLoading = false;
1049
- this.ref.markForCheck();
1050
- });
1051
- }
1052
- }
1063
+ this.openChange$.next($event);
1064
+ // if ($event) {
1065
+ // if (!(this.field.options instanceof Observable)) {
1066
+ // (this.options$ as BehaviorSubject<any[]>).next(this.field.options);
1067
+ // } else {
1068
+ // this.isLoading = true;
1069
+ // this.field.options.pipe(take(1)).subscribe(options => {
1070
+ // (this.options$ as BehaviorSubject<any[]>).next(options);
1071
+ // this.isLoading = false;
1072
+ // this.ref.markForCheck();
1073
+ // });
1074
+ // }
1075
+ // } else {
1076
+ // (this.options$ as BehaviorSubject<any[]>)
1077
+ // .next(this.group.controls[this.field.name].value !== undefined ? [this.group.controls[this.field.name].value] : []);
1078
+ // this.ref.markForCheck();
1079
+ // // this.isLoading = true;
1080
+ // }
1053
1081
  }
1054
1082
  if (this.field.virtualScroll) {
1055
1083
  if ($event) {
@@ -2232,6 +2260,7 @@ class KlesFormSelectSearchComponent extends KlesFieldAbstract {
2232
2260
  this.selectAllControl = new UntypedFormControl(false);
2233
2261
  this.isLoading = false;
2234
2262
  this.optionsFiltered$ = new ReplaySubject(1);
2263
+ this.openChange$ = new Subject();
2235
2264
  this.compareFn = (o1, o2) => {
2236
2265
  if (this.field.property && o1 && o2) {
2237
2266
  return o1[this.field.property] === o2[this.field.property];
@@ -2242,12 +2271,34 @@ class KlesFormSelectSearchComponent extends KlesFieldAbstract {
2242
2271
  ngOnInit() {
2243
2272
  super.ngOnInit();
2244
2273
  if (this.field.lazy) {
2274
+ this.isLoading = true;
2245
2275
  if (this.field.value) {
2246
2276
  this.options$ = new BehaviorSubject(Array.isArray(this.field.value) ? this.field.value : [this.field.value]);
2277
+ this.isLoading = false;
2247
2278
  }
2248
2279
  else {
2249
2280
  this.options$ = new BehaviorSubject([]);
2250
2281
  }
2282
+ this.openChange$
2283
+ .pipe(takeUntil(this._onDestroy), switchMap((isOpen) => {
2284
+ if (isOpen) {
2285
+ if (!(this.field.options instanceof Observable)) {
2286
+ return of(this.field.options);
2287
+ }
2288
+ else {
2289
+ this.isLoading = true;
2290
+ return this.field.options.pipe(take(1));
2291
+ }
2292
+ }
2293
+ else {
2294
+ return of(this.group.controls[this.field.name].value !== undefined ? [this.group.controls[this.field.name].value] : []);
2295
+ }
2296
+ }))
2297
+ .subscribe((options) => {
2298
+ this.options$.next(options);
2299
+ this.isLoading = false;
2300
+ this.ref.markForCheck();
2301
+ });
2251
2302
  }
2252
2303
  else {
2253
2304
  if (!(this.field.options instanceof Observable)) {
@@ -2320,19 +2371,7 @@ class KlesFormSelectSearchComponent extends KlesFieldAbstract {
2320
2371
  }
2321
2372
  openChange($event) {
2322
2373
  if (this.field.lazy) {
2323
- if ($event) {
2324
- if (!(this.field.options instanceof Observable)) {
2325
- this.options$.next(this.field.options);
2326
- }
2327
- else {
2328
- this.isLoading = true;
2329
- this.field.options.pipe(take(1)).subscribe(options => {
2330
- this.options$.next(options);
2331
- this.isLoading = false;
2332
- this.ref.markForCheck();
2333
- });
2334
- }
2335
- }
2374
+ this.openChange$.next($event);
2336
2375
  }
2337
2376
  if (this.field.virtualScroll) {
2338
2377
  if ($event) {