I do not want to use the [clearable]
in ng-select
for leakage of my space. Instead of [clearable]
I want to use only [clearOnBackspace]
but when I write [clearable] = "false"
and [clearOnBackspace] = "true"
it does not work.
enter code here
<ng-select [items]="cities"
bindLabel="name"
placeholder="Select city"
[(ngModel)]="selectedCity"
[clearable]="false"
[clearOnBackspace] = "true"
[excludeGroupsFromDefaultSelection] = "true">
</ng-select>
I do not want to use the [clearable]
in ng-select
for leakage of my space. Instead of [clearable]
I want to use only [clearOnBackspace]
but when I write [clearable] = "false"
and [clearOnBackspace] = "true"
it does not work.
enter code here
<ng-select [items]="cities"
bindLabel="name"
placeholder="Select city"
[(ngModel)]="selectedCity"
[clearable]="false"
[clearOnBackspace] = "true"
[excludeGroupsFromDefaultSelection] = "true">
</ng-select>
Share
Improve this question
edited Jan 28, 2021 at 18:54
Kamil Naja
6,7407 gold badges37 silver badges52 bronze badges
asked Feb 4, 2019 at 5:13
SabbirSabbir
3275 silver badges14 bronze badges
4
- if 'clearable' property is set to false, and clearOnBackspace is set to true, user can remove single item using backspace button. if (this.filterValue || (!multiple && !this.clearable) || !this.clearOnBackspace || !this.hasValue) { template example: <ng-select> (add)=... (remove)=... [multiple]="true" [clearable]="false" [clearOnBackspace]="true" </ng-select> you can hide clear button simply by css – Mebin Joe Commented Feb 4, 2019 at 5:24
-
use
[clearable]="true"
it will be cleared on backspace only – Just code Commented Feb 4, 2019 at 5:36 - The user selects only a single value. So [multiple]="true" not needed. Yap I can remove the cross button using CSS but I want to handle it by JavaScript. – Sabbir Commented Feb 4, 2019 at 5:36
- @Just Code if i make [clearable]="true" it also shows the cross icon. I do not allow it for my space lackage. – Sabbir Commented Feb 4, 2019 at 5:39
1 Answer
Reset to default 3If you do [clearable]="false"
it will disallow to clear the selection.
you can use css to hide the close icon. like this
.ng-clear-wrapper{
display: none;
}
and keep ng-select
as it is
Demo
<ng-select [items]="cities"
bindLabel="name"
placeholder="Select city"
[(ngModel)]="selectedCity"
[clearable]="true"
[clearOnBackspace] = "true"
[excludeGroupsFromDefaultSelection] = "true">
infact you do not need [clearOnBackspace] = "true"
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745614539a4636152.html
评论列表(0条)