Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ export class DnnAutocomplete {

@Watch("value")
handleValueChange(newValue: string) {
this.displayValue = newValue;

// Find the index of the selected item
this.selectedIndex = this.suggestions.findIndex(s => s.value === newValue);
this.selectItemFromValue(newValue);
}

/** attacth the internals for form validation */
Expand All @@ -128,6 +125,12 @@ export class DnnAutocomplete {
this.focused = false;
}
}

componentDidLoad() {
if (this.value != ""){
this.selectItemFromValue(this.value);
}
}

componentDidRender(){
if (this.focused && this.suggestions.length > 0 && !this.positionInitialized){
Expand Down Expand Up @@ -164,6 +167,11 @@ export class DnnAutocomplete {
this.searchQueryChanged.emit(value);
}

private selectItemFromValue(value: string) {
this.selectedIndex = this.suggestions.findIndex(s => s.value === value);
this.displayValue = this.selectedIndex != -1 ? this.suggestions[this.selectedIndex].label : value;
}

private handleInvalid(): void {
this.valid = false;
if (this.customValidityMessage == undefined) {
Expand Down
Loading