@ngx-smz/core 21.10.0-next.19 → 21.10.0-next.20

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.
@@ -1526,7 +1526,7 @@ const CONTROL_FUNCTIONS = {
1526
1526
  if (input.editMode == null)
1527
1527
  input.editMode = 'dialog';
1528
1528
  },
1529
- clear: (control) => { control.patchValue(''); },
1529
+ clear: (control) => { control.patchValue([]); },
1530
1530
  applyDefaultValue: (control, input) => { control.patchValue(input.defaultValue); },
1531
1531
  getValue: (form, input, flattenResponse) => {
1532
1532
  const value = form.get(input.propertyName).value;
@@ -4019,12 +4019,31 @@ class InputListComponent {
4019
4019
  current = null;
4020
4020
  isInlineEditingEnabled = false;
4021
4021
  editForm = null;
4022
+ destroyRef = inject(DestroyRef);
4022
4023
  constructor(cdf, store, actions$, fb) {
4023
4024
  this.cdf = cdf;
4024
4025
  this.store = store;
4025
4026
  this.actions$ = actions$;
4026
4027
  this.fb = fb;
4027
4028
  }
4029
+ ngOnInit() {
4030
+ // A lista e desenhada a partir de `input.listBoxOptions`, nao do controle. Quando o valor do controle muda
4031
+ // por fora (descartar alteracoes, limpar, updateInputValue), reconstroi o estado interno para nao divergir.
4032
+ this.control?.valueChanges?.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((value) => {
4033
+ this.syncFromControl(value);
4034
+ });
4035
+ }
4036
+ syncFromControl(value) {
4037
+ const values = Array.isArray(value) ? value : [];
4038
+ if (JSON.stringify(values) === JSON.stringify(this.input.options ?? []))
4039
+ return;
4040
+ this.input.options = [...values];
4041
+ this.input.listBoxOptions = values.map(x => ({ id: generateGUID(), name: x }));
4042
+ this.current = null;
4043
+ this.isInlineEditingEnabled = false;
4044
+ this.editForm = null;
4045
+ this.cdf.markForCheck();
4046
+ }
4028
4047
  onClick(event) {
4029
4048
  this.isInlineEditingEnabled = false;
4030
4049
  this.editForm = null;