javascript - Ionic show numeric keyboard in ion-searchbar but when a value is selected show name alongside number
问题描述
我有一个带有自动完成功能的ion-searchbar组件
<ion-searchbar #searchBar
no-padding
class="search-bar"
(ionInput)="getCustomers($event)"
[showCancelButton]="true"
[(ngModel)]="customer_text"
[autocomplete]="on"
(ionClear)="clearSearchBar()">
</ion-searchbar>
当离子搜索栏聚焦时,仅显示数字键盘。
当用户从自动完成中选择一个选项时,我需要按数字搜索,但在搜索栏中显示数字和文本。
但是 html 5 验证type=number
妨碍了搜索栏中的任何内容。
解决方案
因为你给了一个输入 type="number" 那么它只会显示你的数字,
所以,我的解决方案是使用 type="text" 然后使用这段代码
html
<ion-searchbar #searchBar
no-padding
class="search-bar"
(keypress)=isNumberKey($event)
(ionInput)="getCustomers($event)"
[showCancelButton]="true"
[(ngModel)]="customer_text"
[autocomplete]="on"
(ionClear)="clearSearchBar()">
</ion-searchbar>
ts
isNumberKey(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
所以,使用这个你只能给输入数字,当你选择它时,它会显示整个选择选项。尝试这个。
推荐阅读
- go - 如何将值重新分配给 Map 的空值输出
- c++ - C++ 将类函数拆分为单独的部分
- json - 如何在 React Native 中向 API 发出 POST 请求?
- java - java - 如何声明一个数组而不必在java中给出一个固定的初始大小?
- count - 创建基因列表
- email - Nginx 访问日志问题
- apache-felix - 在 Felix OSGI 中使用 Java 创建 JAAS 配置
- php - Laravel 从一个表单中插入多条记录
- snakemake - 是否可以将规则动态添加到“localrules:”?
- python-3.x - 所以我正在学习 Python 3.x,这本书想要使用一个循环来打印一个列表。但