Skip to content

Commit

Permalink
fix(autocomplete): fix autocomplete not changing the value when react…
Browse files Browse the repository at this point in the history
…ive forms patch a new value to the control.
  • Loading branch information
William Aguera committed Jul 23, 2019
1 parent d3fb64c commit c3ddfe4
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions projects/truly-ui/src/components/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
SOFTWARE.
*/
import {
Component, Input, Optional, Inject, OnInit, OnChanges, ViewChildren,
Component, Input, Optional, Inject, OnChanges, ViewChildren,
EventEmitter, Output, ChangeDetectorRef, QueryList, AfterViewInit, ViewChild, ElementRef, OnDestroy, ContentChild,
AfterContentInit,
} from '@angular/core';
Expand Down Expand Up @@ -119,6 +119,8 @@ export class TlAutoComplete extends ValueAccessorBase<any> implements OnChanges,

@Output() selectItem: EventEmitter<any> = new EventEmitter();

@Output() changeSelected: EventEmitter<any> = new EventEmitter();

@Output() filter: EventEmitter<any> = new EventEmitter();

@ViewChild( 'input', {static: true} ) input: ElementRef;
Expand Down Expand Up @@ -267,14 +269,13 @@ export class TlAutoComplete extends ValueAccessorBase<any> implements OnChanges,
}

private handleModelLazy() {
if ( this.value && this.lazyMode && !this.modelInitialized ) {
if ( !this.isModelModeString() ) {
this.setDescriptionValue( objectPath.get( this.value, this.keyText ) );
} else {
console.warn( 'The item provided is was not found, emitting filter' );
this.filter.emit( this.getFilters( this.value ) );
if (this.value && this.lazyMode) {
const value = objectPath.get(this.value, this.keyText);
if ( value ) {
this.setDescriptionValue(value);
this.handleKeyModelValue(this.value);
this.changeSelected.emit(this.value);
}
this.handleKeyModelValue( this.value );
}
}

Expand All @@ -283,12 +284,13 @@ export class TlAutoComplete extends ValueAccessorBase<any> implements OnChanges,
}

private handleModelCached() {
if ( this.dataSource && !this.lazyMode && this.dataSource.getCachedData() ) {
this.dataSource.getCachedData().forEach( ( value ) => {
if ( this.dataSource && !this.lazyMode && this.data.length > 0 ) {
this.data.forEach( ( value ) => {
if ( this.value ) {
if ( String( this.getItemCompare( value ) ) === String( this.getCompareModel() ) ) {
this.setDescriptionValue( objectPath.get( value, this.keyText ) );
this.handleKeyModelValue( value );
this.changeSelected.emit( value );
}
}
} );
Expand Down

0 comments on commit c3ddfe4

Please sign in to comment.