matcha-components 20.124.0 → 20.125.0
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.
|
@@ -11591,34 +11591,72 @@ class MatchaAutocompleteTriggerDirective {
|
|
|
11591
11591
|
console.log('MatchaAutocomplete: writeValueToInput chamado', {
|
|
11592
11592
|
displayText,
|
|
11593
11593
|
actualValue,
|
|
11594
|
-
input: this.el.nativeElement
|
|
11594
|
+
input: this.el.nativeElement,
|
|
11595
|
+
hasNgControl: !!this.ngControl
|
|
11595
11596
|
});
|
|
11596
11597
|
const input = this.el.nativeElement;
|
|
11597
|
-
|
|
11598
|
-
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
|
|
11602
|
-
|
|
11598
|
+
// Se há ngControl e actualValue é um objeto (não string), atualizar FormControl diretamente
|
|
11599
|
+
if (this.ngControl && this.ngControl.control && actualValue !== undefined) {
|
|
11600
|
+
// Se actualValue é um objeto, atualizar o FormControl com o objeto completo
|
|
11601
|
+
if (typeof actualValue === 'object' && actualValue !== null) {
|
|
11602
|
+
console.log('MatchaAutocomplete: Atualizando FormControl com objeto', actualValue);
|
|
11603
|
+
// Usar setValue com emitEvent: false para evitar loop infinito, depois emitir manualmente
|
|
11604
|
+
this.ngControl.control.setValue(actualValue, { emitEvent: false });
|
|
11605
|
+
// Atualizar o input visual com o displayText
|
|
11606
|
+
input.value = displayText == null ? '' : String(displayText);
|
|
11607
|
+
// Emitir eventos de mudança manualmente
|
|
11608
|
+
this.ngControl.control.updateValueAndValidity({ emitEvent: true });
|
|
11609
|
+
}
|
|
11610
|
+
else {
|
|
11611
|
+
// Se actualValue é primitivo, atualizar normalmente
|
|
11612
|
+
input.value = displayText == null ? '' : String(displayText);
|
|
11613
|
+
// Dispatch eventos para garantir compatibilidade com Angular Forms
|
|
11614
|
+
const inputEvent = new Event('input', { bubbles: true });
|
|
11615
|
+
const changeEvent = new Event('change', { bubbles: true });
|
|
11616
|
+
input.dispatchEvent(inputEvent);
|
|
11617
|
+
input.dispatchEvent(changeEvent);
|
|
11618
|
+
}
|
|
11619
|
+
}
|
|
11620
|
+
else {
|
|
11621
|
+
// Sem ngControl ou sem actualValue, apenas atualizar o input visual
|
|
11622
|
+
input.value = displayText == null ? '' : String(displayText);
|
|
11623
|
+
// Dispatch eventos para garantir compatibilidade com Angular Forms
|
|
11624
|
+
const inputEvent = new Event('input', { bubbles: true });
|
|
11625
|
+
const changeEvent = new Event('change', { bubbles: true });
|
|
11626
|
+
input.dispatchEvent(inputEvent);
|
|
11627
|
+
input.dispatchEvent(changeEvent);
|
|
11628
|
+
}
|
|
11603
11629
|
// Atualizar visibilidade do botão após escrever valor
|
|
11604
11630
|
setTimeout(() => {
|
|
11605
11631
|
this.updateClearButtonVisibility();
|
|
11606
11632
|
}, 0);
|
|
11607
|
-
console.log('MatchaAutocomplete: Valor escrito no input',
|
|
11633
|
+
console.log('MatchaAutocomplete: Valor escrito no input', {
|
|
11634
|
+
inputValue: input.value,
|
|
11635
|
+
formControlValue: this.ngControl?.control?.value
|
|
11636
|
+
});
|
|
11608
11637
|
}
|
|
11609
11638
|
clearInput() {
|
|
11610
11639
|
const input = this.el.nativeElement;
|
|
11611
11640
|
input.value = '';
|
|
11612
|
-
//
|
|
11613
|
-
|
|
11614
|
-
|
|
11615
|
-
|
|
11616
|
-
|
|
11617
|
-
|
|
11618
|
-
|
|
11641
|
+
// Se há ngControl, limpar o FormControl diretamente
|
|
11642
|
+
if (this.ngControl && this.ngControl.control) {
|
|
11643
|
+
console.log('MatchaAutocomplete: Limpando FormControl');
|
|
11644
|
+
this.ngControl.control.setValue(null, { emitEvent: true });
|
|
11645
|
+
}
|
|
11646
|
+
else {
|
|
11647
|
+
// Sem ngControl, apenas disparar eventos
|
|
11648
|
+
const inputEvent = new Event('input', { bubbles: true });
|
|
11649
|
+
const changeEvent = new Event('change', { bubbles: true });
|
|
11650
|
+
const blurEvent = new Event('blur', { bubbles: true });
|
|
11651
|
+
input.dispatchEvent(inputEvent);
|
|
11652
|
+
input.dispatchEvent(changeEvent);
|
|
11653
|
+
input.dispatchEvent(blurEvent);
|
|
11654
|
+
}
|
|
11619
11655
|
// Atualizar visibilidade do botão
|
|
11620
11656
|
this.updateClearButtonVisibility();
|
|
11621
|
-
console.log('MatchaAutocomplete: Input limpo'
|
|
11657
|
+
console.log('MatchaAutocomplete: Input limpo', {
|
|
11658
|
+
formControlValue: this.ngControl?.control?.value
|
|
11659
|
+
});
|
|
11622
11660
|
}
|
|
11623
11661
|
onClick() {
|
|
11624
11662
|
// Abrir painel quando clicar no input
|