Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Lookup & Autocomplete error state fixes #1928

Merged
merged 5 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 10 additions & 8 deletions src/modules/autocomplete/autocomplete-input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ export class SkyAutocompleteInputDirective

public set displayWith(value: string) {
this._displayWith = value;
this.textValue = this.value[this.displayWith];
this.updateTextValue();
}

public get value() {
return this._value || { };
return this._value;
}

public set value(value: any) {
this._value = value;
this.textValue = this.value[this.displayWith];
this.updateTextValue();
this.onChange(this.value);
this.onTouched();
}
Expand Down Expand Up @@ -100,9 +100,7 @@ export class SkyAutocompleteInputDirective
}

public writeValue(value: any): void {
if (value) {
this.value = value;
}
this.value = value;
}

public registerOnChange(fn: (value: any) => void): void {
Expand All @@ -129,7 +127,7 @@ export class SkyAutocompleteInputDirective

private checkValues(): void {
const text = this.elementRef.nativeElement.value;
const displayValue = this.value[this.displayWith];
const displayValue = this.value ? this.value[this.displayWith] : undefined;

// If the search field contains text, make sure that the value
// matches the selected descriptor key.
Expand All @@ -140,9 +138,13 @@ export class SkyAutocompleteInputDirective
} else {
// The search field is empty (or doesn't have a selected item),
// so clear out the selected value.
this.value = { };
this.value = undefined;
}

this.blur.emit();
}

private updateTextValue() {
this.textValue = this.value ? this.value[this.displayWith] : undefined;
}
}
4 changes: 2 additions & 2 deletions src/modules/autocomplete/autocomplete.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ describe('Autocomplete component', () => {
SkyAppTestUtility.fireDomEvent(inputElement, 'blur');
tick();

expect(component.myForm.value.favoriteColor).toEqual({ });
expect(input.value).toEqual({ });
expect(component.myForm.value.favoriteColor).toBeUndefined();
expect(input.value).toBeUndefined();
expect(inputElement.value).toEqual('');
})
);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/lookup/lookup.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@
flex-basis: 100px;
}
}

:host(.ng-invalid.ng-touched) .sky-lookup-search {
@include sky-field-status(invalid);
}