【发布时间】:2013-06-11 15:15:06
【问题描述】:
我正在将http://www.greywyvern.com/code/javascript/keyboard 中的虚拟键盘添加到 extjs 4.2 表单的文本字段中。
它基本上可以工作,见这里:http://jsfiddle.net/g5VN8/1/
1) 我的第一个问题是:这真的是连接它们的最佳方式吗?用计时器而不是事件来保持 extjs 值是最新的,对我来说看起来很丑。
另外我无法克服以下两个问题:
2) 键盘图标换行。它应该位于字段的末尾,在右侧,就像这里的示例一样:http://www.greywyvern.com/code/javascript/keyboard
3) 字段焦点不起作用。我有它在一个节目听众。即使包装在 window.setTimeout() 中,它也不起作用,因此这不是时间问题。不会抛出任何错误。
这是一个复制粘贴(stackoverflow 的规则)。我会及时更新这两个地方。
Ext.onReady(function() {
Ext.QuickTips.init();
var formPanel = Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
bodyStyle: 'padding: 5px 5px 0 5px;',
defaults: {
anchor: '100%',
},
items: [{
xtype:'textfield',
name: 'string',
fieldLabel: 'String',
maxLength:30, enforceMaxLength:true,
allowBlank: false,
listeners: {
show: function(field) {
//focus the field when the window shows
field.focus(true, 1000); //TODO: doesn't work, no error
},
afterrender:function(cmp){
cmp.inputEl.set({ //see http://jsfiddle.net/4TSDu/19/
autocomplete:'on'
});
//attach the keyboard
//because it modifies the dom directly we need to hack it to
//inform extjs (really, ext has no such listener option?)
var interval = window.setInterval(function() {
try {
var newValue = cmp.inputEl.dom.value;
var oldValue = cmp.getValue();
if (newValue != oldValue) {
//only do it then, cause it also moves the cursor
//to the end and that sucks.
cmp.setValue( newValue );
}
} catch (e) {
//form was removed
window.clearInterval(interval);
}
}, 100);
// see http://www.greywyvern.com/code/javascript/keyboard
VKI_attach(cmp.inputEl.dom);
}
}
}],
buttons: [{
text: 'Alert string',
handler: function() {
var stringField = this.up('form').getForm().findField('string');
alert(stringField.getValue());
}
}]
});
});
【问题讨论】:
标签: javascript extjs4.2