遗憾的是,我没有找到任何焦点事件sap.m.Input
or sap.m.TextArea
我可以在 XML 视图中注册处理程序。
您的最佳实践是什么,例如如果你有近 100 个字段并且其中大部分应该处理focus 事件,以便自动选择输入字段中的文本?
通常,我会尽量避免注册focusin
控制器中每个输入字段的处理程序(也循环),但似乎没有其他可用的可能性,不是吗?
What I want is a possibility, that when I navigate e.g. with keyboard through a table with input fields, every time when I press the tab or updown arrow keys to jump to next input field, the whole content of the input field should be selected.
Example:
- 打开这个表格样本 https://openui5.hana.ondemand.com/entity/sap.m.Table/sample/sap.m.sample.TableEditable.
- Click on Edit.
- When tabbing, it automatically selects the text. But it doesn't work with updown arrow keys and with
sap.m.Input
class.
这是一个扩展的工作示例sap.m.Input
选择焦点文本:https://embed.plnkr.co/98BIbMEIujbzBXqU https://embed.plnkr.co/98BIbMEIujbzBXqU
Input.extend("demo.control.Input", {
onfocusin: function() {
if (typeof Input.prototype.onfocusin == "function") {
Input.prototype.onfocusin.apply(this, arguments);
}
this.getDomRef("inner").select();
},
// ...
});
Note: sap.m.InputBase
提供APIselectText(iStart, iEnd)
。但是,该 API 不支持类型的输入控件Number
根据HTML 规范 https://html.spec.whatwg.org/multipage/input.html#input-type-attr-summary以及 API 参考:
selectText
仅支持输入控件的类型Text
, Url
, Tel
and Password
.
Since our goal is to select all text within the input field (not a range) regardless of the type, domElement.select()
api https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select can be used instead.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)