ngx-sp-infra 6.0.4 → 6.0.5
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.
|
@@ -6376,6 +6376,7 @@ class LibComboboxReworkComponent {
|
|
|
6376
6376
|
// Getter/Setter para o valor
|
|
6377
6377
|
get value() { return this._value; }
|
|
6378
6378
|
set value(val) {
|
|
6379
|
+
console.log(val);
|
|
6379
6380
|
if (val !== this._value) {
|
|
6380
6381
|
this._value = val;
|
|
6381
6382
|
this._onChange(val); // Notifica o FormControl sobre a mudança
|
|
@@ -6525,14 +6526,50 @@ class LibComboboxReworkComponent {
|
|
|
6525
6526
|
}
|
|
6526
6527
|
return this.compare(item, this.value);
|
|
6527
6528
|
}
|
|
6529
|
+
/**
|
|
6530
|
+
* "Harmoniza" um valor primitivo de "ID" e encontra o seu item correspondente na lista
|
|
6531
|
+
* @param val Valor a ser resolvido
|
|
6532
|
+
* @returns O item correspondente ou null
|
|
6533
|
+
*/
|
|
6534
|
+
resolveValue(val) {
|
|
6535
|
+
// Se já é um objeto com a propriedade customValue, retorna direto
|
|
6536
|
+
if (typeof val === 'object' && val !== null && val[this.customValue] !== undefined) {
|
|
6537
|
+
return val;
|
|
6538
|
+
}
|
|
6539
|
+
// Se é um valor primitivo, tenta encontrar na lista
|
|
6540
|
+
const match = this.list?.find((item) => item[this.customValue] === val);
|
|
6541
|
+
return match ?? null;
|
|
6542
|
+
}
|
|
6528
6543
|
// #endregion Seleção
|
|
6529
6544
|
// #region VALUE_ACCESSOR do Angular
|
|
6545
|
+
// // Método antigo
|
|
6546
|
+
// public writeValue(obj: T | T[] | null): void {
|
|
6547
|
+
// console.log(obj);
|
|
6548
|
+
// if (!obj) this.selectedValues = null;
|
|
6549
|
+
// this._onTouched();
|
|
6550
|
+
// if (this.multiple && obj) {
|
|
6551
|
+
// this.selectedValues = Array.isArray(obj) ? [...obj] : [];
|
|
6552
|
+
// if (this.selectedValues.length === 0) this.selectedValues = null;
|
|
6553
|
+
// this.value = this.selectedValues;
|
|
6554
|
+
// this._onChange(this.selectedValues);
|
|
6555
|
+
// this.selectionChange.emit(this.selectedValues);
|
|
6556
|
+
// }
|
|
6557
|
+
// else {
|
|
6558
|
+
// this.value = obj;
|
|
6559
|
+
// this._onChange(obj);
|
|
6560
|
+
// this.selectionChange.emit(obj);
|
|
6561
|
+
// }
|
|
6562
|
+
// this._cdr.markForCheck();
|
|
6563
|
+
// }
|
|
6530
6564
|
writeValue(obj) {
|
|
6565
|
+
console.log(obj);
|
|
6531
6566
|
if (!obj)
|
|
6532
6567
|
this.selectedValues = null;
|
|
6533
6568
|
this._onTouched();
|
|
6534
6569
|
if (this.multiple && obj) {
|
|
6535
|
-
this.selectedValues = Array.isArray(obj)
|
|
6570
|
+
this.selectedValues = Array.isArray(obj)
|
|
6571
|
+
? obj.map(val => this.resolveValue(val)).filter((v) => v !== null)
|
|
6572
|
+
: [];
|
|
6536
6573
|
if (this.selectedValues.length === 0)
|
|
6537
6574
|
this.selectedValues = null;
|
|
6538
6575
|
this.value = this.selectedValues;
|
|
@@ -6540,9 +6577,10 @@ class LibComboboxReworkComponent {
|
|
|
6540
6577
|
this.selectionChange.emit(this.selectedValues);
|
|
6541
6578
|
}
|
|
6542
6579
|
else {
|
|
6543
|
-
|
|
6544
|
-
this.
|
|
6545
|
-
this.
|
|
6580
|
+
const resolved = this.resolveValue(obj);
|
|
6581
|
+
this.value = resolved;
|
|
6582
|
+
this._onChange(resolved);
|
|
6583
|
+
this.selectionChange.emit(resolved);
|
|
6546
6584
|
}
|
|
6547
6585
|
this._cdr.markForCheck();
|
|
6548
6586
|
}
|