How to fix this search filters for both upper case & lover case typing in Angular?
I found a search with filters Angular example here yesterday. Tried to make some changes on it and after that couldn't overcome these 2 challenges?
- When you type the name in lower case it doesn't give any result. It must completely match for working. While how can it be changed? So even if the user searches with lower case and types the correct name it finds the result? At the moment it requires uppercase as it provided in data.
- How can I implement autocomplete feature? So when a user types first characters it displays suggestions for that input?
Here is the code:
Pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter',
})
export class FilterPipe implements PipeTransform {
transform(items: any, value: string): any {
if (!items) return ;
if (!value) return items;
return items.filter(singleItem =>
singleItem['name'].toLowerCase().includes(value.toLowerCase())
);
}
}
TypeScript
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormControl, FormBuilder } from '@angular/forms';
import { UserService } from '../user.service';
@Component({
selector: 'app-search',
templateUrl: './search.component.html'
})
export class SearchComponent implements OnInit {
form: FormGroup;
@Output() autoSearch: EventEmitter<string> = new EventEmitter<string>();
@Output() groupFilters: EventEmitter<any> = new EventEmitter<any>();
constructor(private fb: FormBuilder,
private userService: UserService) {}
ngOnInit(): void {
this.buildForm();
}
buildForm(): void {
this.form = this.fb.group({
name: new FormControl(''),
prefix: new FormControl(''),
position: new FormControl(''),
gender: new FormControl('')
});
}
search(filters: any): void {
Object.keys(filters).forEach(key => filters[key] === '' ? delete filters[key] : key);
this.groupFilters.emit(filters);
}
}
HTML
<h3>Group Filter</h3>
<div class="row">
<div class="col-md-3">
<input type="text"
formControlName="name"
class="form-control"
placeholder="name"
#searchText
/>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="prefix">
<option value="">Prefix</option>
<option value="MR">MR</option>
<option value="MS">MS</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="position">
<option value="">Position</option>
<option value="admin">admin</option>
<option value="student">student</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="gender">
<option value="">Gender</option>
<option value="M">male</option>
<option value="F">female</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<button class="btn btn-primary"
(click)="search(form.value)">Search</button>
</div>
</div>
</form><br/>
How can I solve above mentioned 2 challenges?
If you need the complete example then here is the link:
https://stackblitz.com/edit/ng6-multiple-search-values-s1xapc?file=src%2Fapp%2Fuser%2Ffilter.pipe.ts
angular6
add a comment |
I found a search with filters Angular example here yesterday. Tried to make some changes on it and after that couldn't overcome these 2 challenges?
- When you type the name in lower case it doesn't give any result. It must completely match for working. While how can it be changed? So even if the user searches with lower case and types the correct name it finds the result? At the moment it requires uppercase as it provided in data.
- How can I implement autocomplete feature? So when a user types first characters it displays suggestions for that input?
Here is the code:
Pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter',
})
export class FilterPipe implements PipeTransform {
transform(items: any, value: string): any {
if (!items) return ;
if (!value) return items;
return items.filter(singleItem =>
singleItem['name'].toLowerCase().includes(value.toLowerCase())
);
}
}
TypeScript
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormControl, FormBuilder } from '@angular/forms';
import { UserService } from '../user.service';
@Component({
selector: 'app-search',
templateUrl: './search.component.html'
})
export class SearchComponent implements OnInit {
form: FormGroup;
@Output() autoSearch: EventEmitter<string> = new EventEmitter<string>();
@Output() groupFilters: EventEmitter<any> = new EventEmitter<any>();
constructor(private fb: FormBuilder,
private userService: UserService) {}
ngOnInit(): void {
this.buildForm();
}
buildForm(): void {
this.form = this.fb.group({
name: new FormControl(''),
prefix: new FormControl(''),
position: new FormControl(''),
gender: new FormControl('')
});
}
search(filters: any): void {
Object.keys(filters).forEach(key => filters[key] === '' ? delete filters[key] : key);
this.groupFilters.emit(filters);
}
}
HTML
<h3>Group Filter</h3>
<div class="row">
<div class="col-md-3">
<input type="text"
formControlName="name"
class="form-control"
placeholder="name"
#searchText
/>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="prefix">
<option value="">Prefix</option>
<option value="MR">MR</option>
<option value="MS">MS</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="position">
<option value="">Position</option>
<option value="admin">admin</option>
<option value="student">student</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="gender">
<option value="">Gender</option>
<option value="M">male</option>
<option value="F">female</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<button class="btn btn-primary"
(click)="search(form.value)">Search</button>
</div>
</div>
</form><br/>
How can I solve above mentioned 2 challenges?
If you need the complete example then here is the link:
https://stackblitz.com/edit/ng6-multiple-search-values-s1xapc?file=src%2Fapp%2Fuser%2Ffilter.pipe.ts
angular6
add a comment |
I found a search with filters Angular example here yesterday. Tried to make some changes on it and after that couldn't overcome these 2 challenges?
- When you type the name in lower case it doesn't give any result. It must completely match for working. While how can it be changed? So even if the user searches with lower case and types the correct name it finds the result? At the moment it requires uppercase as it provided in data.
- How can I implement autocomplete feature? So when a user types first characters it displays suggestions for that input?
Here is the code:
Pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter',
})
export class FilterPipe implements PipeTransform {
transform(items: any, value: string): any {
if (!items) return ;
if (!value) return items;
return items.filter(singleItem =>
singleItem['name'].toLowerCase().includes(value.toLowerCase())
);
}
}
TypeScript
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormControl, FormBuilder } from '@angular/forms';
import { UserService } from '../user.service';
@Component({
selector: 'app-search',
templateUrl: './search.component.html'
})
export class SearchComponent implements OnInit {
form: FormGroup;
@Output() autoSearch: EventEmitter<string> = new EventEmitter<string>();
@Output() groupFilters: EventEmitter<any> = new EventEmitter<any>();
constructor(private fb: FormBuilder,
private userService: UserService) {}
ngOnInit(): void {
this.buildForm();
}
buildForm(): void {
this.form = this.fb.group({
name: new FormControl(''),
prefix: new FormControl(''),
position: new FormControl(''),
gender: new FormControl('')
});
}
search(filters: any): void {
Object.keys(filters).forEach(key => filters[key] === '' ? delete filters[key] : key);
this.groupFilters.emit(filters);
}
}
HTML
<h3>Group Filter</h3>
<div class="row">
<div class="col-md-3">
<input type="text"
formControlName="name"
class="form-control"
placeholder="name"
#searchText
/>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="prefix">
<option value="">Prefix</option>
<option value="MR">MR</option>
<option value="MS">MS</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="position">
<option value="">Position</option>
<option value="admin">admin</option>
<option value="student">student</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="gender">
<option value="">Gender</option>
<option value="M">male</option>
<option value="F">female</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<button class="btn btn-primary"
(click)="search(form.value)">Search</button>
</div>
</div>
</form><br/>
How can I solve above mentioned 2 challenges?
If you need the complete example then here is the link:
https://stackblitz.com/edit/ng6-multiple-search-values-s1xapc?file=src%2Fapp%2Fuser%2Ffilter.pipe.ts
angular6
I found a search with filters Angular example here yesterday. Tried to make some changes on it and after that couldn't overcome these 2 challenges?
- When you type the name in lower case it doesn't give any result. It must completely match for working. While how can it be changed? So even if the user searches with lower case and types the correct name it finds the result? At the moment it requires uppercase as it provided in data.
- How can I implement autocomplete feature? So when a user types first characters it displays suggestions for that input?
Here is the code:
Pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter',
})
export class FilterPipe implements PipeTransform {
transform(items: any, value: string): any {
if (!items) return ;
if (!value) return items;
return items.filter(singleItem =>
singleItem['name'].toLowerCase().includes(value.toLowerCase())
);
}
}
TypeScript
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormControl, FormBuilder } from '@angular/forms';
import { UserService } from '../user.service';
@Component({
selector: 'app-search',
templateUrl: './search.component.html'
})
export class SearchComponent implements OnInit {
form: FormGroup;
@Output() autoSearch: EventEmitter<string> = new EventEmitter<string>();
@Output() groupFilters: EventEmitter<any> = new EventEmitter<any>();
constructor(private fb: FormBuilder,
private userService: UserService) {}
ngOnInit(): void {
this.buildForm();
}
buildForm(): void {
this.form = this.fb.group({
name: new FormControl(''),
prefix: new FormControl(''),
position: new FormControl(''),
gender: new FormControl('')
});
}
search(filters: any): void {
Object.keys(filters).forEach(key => filters[key] === '' ? delete filters[key] : key);
this.groupFilters.emit(filters);
}
}
HTML
<h3>Group Filter</h3>
<div class="row">
<div class="col-md-3">
<input type="text"
formControlName="name"
class="form-control"
placeholder="name"
#searchText
/>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="prefix">
<option value="">Prefix</option>
<option value="MR">MR</option>
<option value="MS">MS</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="position">
<option value="">Position</option>
<option value="admin">admin</option>
<option value="student">student</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<select class="form-control"
formControlName="gender">
<option value="">Gender</option>
<option value="M">male</option>
<option value="F">female</option>
</select>
</div>
<div class="col-md-3 col-sm-3">
<button class="btn btn-primary"
(click)="search(form.value)">Search</button>
</div>
</div>
</form><br/>
How can I solve above mentioned 2 challenges?
If you need the complete example then here is the link:
https://stackblitz.com/edit/ng6-multiple-search-values-s1xapc?file=src%2Fapp%2Fuser%2Ffilter.pipe.ts
angular6
angular6
edited Jan 12 at 9:19
NewTech Lover
asked Nov 22 '18 at 9:40
NewTech LoverNewTech Lover
124312
124312
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
For 1st question : I forked your example and Solve the issue that faced you and enhance the pipe filter to be more generic you can check the solution here:
https://stackblitz.com/edit/ng6-multiple-search-values-smz1cb-solved?file=src%2Fapp%2Fuser%2Fuser-list%2Fuser-list.component.ts
For 2nd question : I suggest you to use this plugin with angular its documentation is very clear and well organized and you will find your case on it it's :
ng-select
Updated:
You can find the solution for 2nd question in the same stackblitz link
hope my answer helps you.
Thanks for solving the first one. Is there another way for 2nd one without any additional dependency?
– NewTech Lover
Nov 22 '18 at 10:29
Yes Of Course ! you can make the same technique they use in their library , you make a div under the input field and put all the items name on it and display the items that includes the user input
– Shorbagy
Nov 22 '18 at 10:48
Their code is a bit confusing. I need autocomplete only for name input in the above example. They did something different with select.
– NewTech Lover
Nov 22 '18 at 11:04
I update my answer with a solution for 2nd question check it !
– Shorbagy
Nov 22 '18 at 11:20
1
I think you will have to make a lot of work and wrap the name input with another component to display the names first and make a bind value with input event of name input and this component and apply the same pipe filter to it and also handle the enter event and click event when user did that I think ng-select make all of that for you already
– Shorbagy
Nov 22 '18 at 11:34
|
show 5 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427910%2fhow-to-fix-this-search-filters-for-both-upper-case-lover-case-typing-in-angula%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For 1st question : I forked your example and Solve the issue that faced you and enhance the pipe filter to be more generic you can check the solution here:
https://stackblitz.com/edit/ng6-multiple-search-values-smz1cb-solved?file=src%2Fapp%2Fuser%2Fuser-list%2Fuser-list.component.ts
For 2nd question : I suggest you to use this plugin with angular its documentation is very clear and well organized and you will find your case on it it's :
ng-select
Updated:
You can find the solution for 2nd question in the same stackblitz link
hope my answer helps you.
Thanks for solving the first one. Is there another way for 2nd one without any additional dependency?
– NewTech Lover
Nov 22 '18 at 10:29
Yes Of Course ! you can make the same technique they use in their library , you make a div under the input field and put all the items name on it and display the items that includes the user input
– Shorbagy
Nov 22 '18 at 10:48
Their code is a bit confusing. I need autocomplete only for name input in the above example. They did something different with select.
– NewTech Lover
Nov 22 '18 at 11:04
I update my answer with a solution for 2nd question check it !
– Shorbagy
Nov 22 '18 at 11:20
1
I think you will have to make a lot of work and wrap the name input with another component to display the names first and make a bind value with input event of name input and this component and apply the same pipe filter to it and also handle the enter event and click event when user did that I think ng-select make all of that for you already
– Shorbagy
Nov 22 '18 at 11:34
|
show 5 more comments
For 1st question : I forked your example and Solve the issue that faced you and enhance the pipe filter to be more generic you can check the solution here:
https://stackblitz.com/edit/ng6-multiple-search-values-smz1cb-solved?file=src%2Fapp%2Fuser%2Fuser-list%2Fuser-list.component.ts
For 2nd question : I suggest you to use this plugin with angular its documentation is very clear and well organized and you will find your case on it it's :
ng-select
Updated:
You can find the solution for 2nd question in the same stackblitz link
hope my answer helps you.
Thanks for solving the first one. Is there another way for 2nd one without any additional dependency?
– NewTech Lover
Nov 22 '18 at 10:29
Yes Of Course ! you can make the same technique they use in their library , you make a div under the input field and put all the items name on it and display the items that includes the user input
– Shorbagy
Nov 22 '18 at 10:48
Their code is a bit confusing. I need autocomplete only for name input in the above example. They did something different with select.
– NewTech Lover
Nov 22 '18 at 11:04
I update my answer with a solution for 2nd question check it !
– Shorbagy
Nov 22 '18 at 11:20
1
I think you will have to make a lot of work and wrap the name input with another component to display the names first and make a bind value with input event of name input and this component and apply the same pipe filter to it and also handle the enter event and click event when user did that I think ng-select make all of that for you already
– Shorbagy
Nov 22 '18 at 11:34
|
show 5 more comments
For 1st question : I forked your example and Solve the issue that faced you and enhance the pipe filter to be more generic you can check the solution here:
https://stackblitz.com/edit/ng6-multiple-search-values-smz1cb-solved?file=src%2Fapp%2Fuser%2Fuser-list%2Fuser-list.component.ts
For 2nd question : I suggest you to use this plugin with angular its documentation is very clear and well organized and you will find your case on it it's :
ng-select
Updated:
You can find the solution for 2nd question in the same stackblitz link
hope my answer helps you.
For 1st question : I forked your example and Solve the issue that faced you and enhance the pipe filter to be more generic you can check the solution here:
https://stackblitz.com/edit/ng6-multiple-search-values-smz1cb-solved?file=src%2Fapp%2Fuser%2Fuser-list%2Fuser-list.component.ts
For 2nd question : I suggest you to use this plugin with angular its documentation is very clear and well organized and you will find your case on it it's :
ng-select
Updated:
You can find the solution for 2nd question in the same stackblitz link
hope my answer helps you.
edited Nov 22 '18 at 11:22
answered Nov 22 '18 at 10:19
ShorbagyShorbagy
1713
1713
Thanks for solving the first one. Is there another way for 2nd one without any additional dependency?
– NewTech Lover
Nov 22 '18 at 10:29
Yes Of Course ! you can make the same technique they use in their library , you make a div under the input field and put all the items name on it and display the items that includes the user input
– Shorbagy
Nov 22 '18 at 10:48
Their code is a bit confusing. I need autocomplete only for name input in the above example. They did something different with select.
– NewTech Lover
Nov 22 '18 at 11:04
I update my answer with a solution for 2nd question check it !
– Shorbagy
Nov 22 '18 at 11:20
1
I think you will have to make a lot of work and wrap the name input with another component to display the names first and make a bind value with input event of name input and this component and apply the same pipe filter to it and also handle the enter event and click event when user did that I think ng-select make all of that for you already
– Shorbagy
Nov 22 '18 at 11:34
|
show 5 more comments
Thanks for solving the first one. Is there another way for 2nd one without any additional dependency?
– NewTech Lover
Nov 22 '18 at 10:29
Yes Of Course ! you can make the same technique they use in their library , you make a div under the input field and put all the items name on it and display the items that includes the user input
– Shorbagy
Nov 22 '18 at 10:48
Their code is a bit confusing. I need autocomplete only for name input in the above example. They did something different with select.
– NewTech Lover
Nov 22 '18 at 11:04
I update my answer with a solution for 2nd question check it !
– Shorbagy
Nov 22 '18 at 11:20
1
I think you will have to make a lot of work and wrap the name input with another component to display the names first and make a bind value with input event of name input and this component and apply the same pipe filter to it and also handle the enter event and click event when user did that I think ng-select make all of that for you already
– Shorbagy
Nov 22 '18 at 11:34
Thanks for solving the first one. Is there another way for 2nd one without any additional dependency?
– NewTech Lover
Nov 22 '18 at 10:29
Thanks for solving the first one. Is there another way for 2nd one without any additional dependency?
– NewTech Lover
Nov 22 '18 at 10:29
Yes Of Course ! you can make the same technique they use in their library , you make a div under the input field and put all the items name on it and display the items that includes the user input
– Shorbagy
Nov 22 '18 at 10:48
Yes Of Course ! you can make the same technique they use in their library , you make a div under the input field and put all the items name on it and display the items that includes the user input
– Shorbagy
Nov 22 '18 at 10:48
Their code is a bit confusing. I need autocomplete only for name input in the above example. They did something different with select.
– NewTech Lover
Nov 22 '18 at 11:04
Their code is a bit confusing. I need autocomplete only for name input in the above example. They did something different with select.
– NewTech Lover
Nov 22 '18 at 11:04
I update my answer with a solution for 2nd question check it !
– Shorbagy
Nov 22 '18 at 11:20
I update my answer with a solution for 2nd question check it !
– Shorbagy
Nov 22 '18 at 11:20
1
1
I think you will have to make a lot of work and wrap the name input with another component to display the names first and make a bind value with input event of name input and this component and apply the same pipe filter to it and also handle the enter event and click event when user did that I think ng-select make all of that for you already
– Shorbagy
Nov 22 '18 at 11:34
I think you will have to make a lot of work and wrap the name input with another component to display the names first and make a bind value with input event of name input and this component and apply the same pipe filter to it and also handle the enter event and click event when user did that I think ng-select make all of that for you already
– Shorbagy
Nov 22 '18 at 11:34
|
show 5 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427910%2fhow-to-fix-this-search-filters-for-both-upper-case-lover-case-typing-in-angula%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown