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

Commit

Permalink
Worked on verifying required error states for lookup and autocomplete…
Browse files Browse the repository at this point in the history
… components (#1928)

Resolves #1921
  • Loading branch information
Blackbaud-TrevorBurch authored Aug 27, 2018
1 parent 235fd48 commit 8dccd37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
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 @@ -55,3 +55,7 @@
flex-basis: 100px;
}
}

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

0 comments on commit 8dccd37

Please sign in to comment.