Skip to content

Commit

Permalink
(feat): Lowercase matching on selection. Fixes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Nov 14, 2017
1 parent 4f50fb6 commit 1689729
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions demo/src/app/typeahead/typeahead.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,18 @@ export class TypeaheadComponent implements ControlValueAccessor, AfterViewInit,
}

private hasMatch(value: string | Object): boolean {
const sanitizedValue = typeof value === 'string' ? sanitizeString(value) : null;

for (const key in this.matches) {
if (typeof this.matches[key] === 'string') {
if (this.matches[key] === value) {
const sanitizedMatch = sanitizeString(<string> this.matches[key]);
if (sanitizedMatch === sanitizedValue) {
return true;
}
} else {
if (typeof value === 'string') {
if ((<any> this.matches[key])[this.nameField] === value) {
const sanitizedMatch = sanitizeString((<Object> this.matches[key])[this.nameField]);
if (sanitizedMatch === sanitizedValue) {
return true;
}
} else {
Expand Down Expand Up @@ -516,7 +520,8 @@ export class TypeaheadComponent implements ControlValueAccessor, AfterViewInit,
private extractIdentifier(value: string | Object) {
if (this.complex) {
if (typeof value === 'string') {
const match: Object = (<Object[]> this.allMatches).find(item => item[this.nameField] === value);
const sanitizedValue = sanitizeString(value);
const match: Object = (<Object[]> this.allMatches).find(item => sanitizeString(item[this.nameField]) === sanitizedValue);
if (match) {
return match[this.idField];
}
Expand Down
11 changes: 8 additions & 3 deletions src/typeahead.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,18 @@ export class TypeaheadComponent implements ControlValueAccessor, AfterViewInit,
}

private hasMatch(value: string | Object): boolean {
const sanitizedValue = typeof value === 'string' ? sanitizeString(value) : null;

for (const key in this.matches) {
if (typeof this.matches[key] === 'string') {
if (this.matches[key] === value) {
const sanitizedMatch = sanitizeString(<string> this.matches[key]);
if (sanitizedMatch === sanitizedValue) {
return true;
}
} else {
if (typeof value === 'string') {
if ((<any> this.matches[key])[this.nameField] === value) {
const sanitizedMatch = sanitizeString((<Object> this.matches[key])[this.nameField]);
if (sanitizedMatch === sanitizedValue) {
return true;
}
} else {
Expand Down Expand Up @@ -516,7 +520,8 @@ export class TypeaheadComponent implements ControlValueAccessor, AfterViewInit,
private extractIdentifier(value: string | Object) {
if (this.complex) {
if (typeof value === 'string') {
const match: Object = (<Object[]> this.allMatches).find(item => item[this.nameField] === value);
const sanitizedValue = sanitizeString(value);
const match: Object = (<Object[]> this.allMatches).find(item => sanitizeString(item[this.nameField]) === sanitizedValue);
if (match) {
return match[this.idField];
}
Expand Down

0 comments on commit 1689729

Please sign in to comment.