使用屏幕键盘提交表单
我正在尝试使用屏幕键盘提交表单,但不知道如何处理。本质上,当我单击表单上的提交按钮时,我需要能够看到在屏幕键盘中单击的字符。
我有一个指令,其中包含用于列出事件的方法,例如 onFocus
onBlur
。我有一个组件,列出了不同的按键和鼠标事件,例如 keyPressed
_enterPressed
等。
下面的 stackblitz 链接,
这是我的代码和service.ts
private _enterPressed: Subject<void>;
get enterPressed() {
return this._enterPressed;
}
fireEnterPressed() {
this._enterPressed.next();
}
指令
private onEnter() {
let element = this.el.nativeElement;
let inputEl = element.querySelector('input');
alert("Enter"+ inputEl.value);
}
app component.ts
submit() {
//submit forms
alert('submit');
}
这里是stackblitz 代码示例 https://stackblitz.com/edit/onscreen-keyboard-5uxhyo?file=src%2Fapp%2Fapp.component.ts
当我使用屏幕键盘在输入字段中输入字符时,并且然后我单击“提交”按钮,我看不到输入的字符,但是如果我在计算机键盘上正常键入并单击“提交”,那么我可以看到警报的值。
知道我该如何解决这个问题吗?
I am trying to submit a form using an on screen keyboard but am not sure how to go about this. Essentially I need be able to see the characters that I click on in the on screen keyboard when I click the submit button on my form.
I have a directive that has the methods I use for listing the events like onFocus
onBlur
. I have a component that lists the different key and mouse events like keyPressed
_enterPressed
etc.
Here is my code and a stackblitz link below
service.ts
private _enterPressed: Subject<void>;
get enterPressed() {
return this._enterPressed;
}
fireEnterPressed() {
this._enterPressed.next();
}
directive
private onEnter() {
let element = this.el.nativeElement;
let inputEl = element.querySelector('input');
alert("Enter"+ inputEl.value);
}
app component.ts
submit() {
//submit forms
alert('submit');
}
Here is a stackblitz example of the code https://stackblitz.com/edit/onscreen-keyboard-5uxhyo?file=src%2Fapp%2Fapp.component.ts
When I use the on screen keyboard to input characters into the input fields, and then I click the submit button I do not see the characters that I have entered however if I type normally on my computers keyboard and click submit then i can see the values alerted.
Any idea how I can fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的键盘仅更改“element.value”。
您可以在
osk-input.directive
中注入“NgControl”,并在函数
onKey
和onBackspace
中添加 this.control.control.setValue (...)顺便提一句。你的 onEnterFunction 应该像
这样,你可以在 .html 中使用你
的 分叉 stackblitz
Your keyboard only change the "element.value".
You can inject the "NgControl" in your
osk-input.directive
And in your functions
onKey
andonBackspace
add this.control.control.setValue(...)BTW. Your onEnterFunction should be some like
So, you can use in your .html like
Your forked stackblitz