当我在Ext.form.field.HtmlEditor(xtype:'htmleditor')中输入文本时,用户按ctrl + enter时,我正在尝试发出ajax请求,但我不知道该怎么做。 />
我在'htmleditor'旁边的按钮可以发送'htmleditor'的值但是我想用ctrl + enter添加该操作的键盘快捷键。
将会感激一些帮助。
this.htmleditor = this.addComment.add({
region:'center',
xtype:'htmleditor',
margin:'0 0 0 0',
enableSourceEdit:false,
height:200
});
答案 0 :(得分:4)
您无法侦听默认htmleditor中的事件。所以你需要使用它的更新版本。
此代码可以帮助您(它适用于extjs 3,因此您可能需要将其更改为4版本):
Cyber.ui.HtmlEditor = Ext.extend(Ext.form.HtmlEditor, {
frame : true,
initComponent : function() {
Cyber.ui.HtmlEditor.superclass.initComponent.call(this);
this.addEvents('submit');
},
initEditor : function() {
Cyber.ui.HtmlEditor.superclass.initEditor.call(this);
if (Ext.isGecko) {
Ext.EventManager.on(this.doc, 'keypress', this.fireSubmit,
this);
}
if (Ext.isIE || Ext.isWebKit || Ext.isOpera) {
Ext.EventManager.on(this.doc, 'keydown', this.fireSubmit,
this);
}
},
fireSubmit : function(e) {
if (e.ctrlKey && Ext.EventObject.ENTER == e.getKey()) {
// Do what you need here
}
}
});
Ext.reg('customeditor', Cyber.ui.HtmlEditor);
以你的形式:
this.htmleditor = this.addComment.add({
region:'center',
xtype:'customeditor',
margin:'0 0 0 0',
enableSourceEdit:false,
height:200
});
我使用Extjs 4玩了很多并找到了方法(你需要在使用htmleditor之前包含这段代码):
Ext.form.HtmlEditor.override({
frame : true,
initComponent: function() {
this.callOverridden();
this.addEvents('submit');
},
initEditor : function() {
this.callOverridden();
var me = this;
var doc = me.getDoc();
if (Ext.isGecko) {
Ext.EventManager.on(doc, 'keypress', me.fireSubmit, me);
}
if (Ext.isIE || Ext.isWebKit || Ext.isOpera) {
Ext.EventManager.on(doc, 'keydown', me.fireSubmit, me);
}
},
fireSubmit : function(e) {
if (e.ctrlKey && Ext.EventObject.ENTER == e.getKey()) {
// Do what you need here
alert('yes!');
}
}
});
答案 1 :(得分:0)
this你所追求的是什么(已经在堆栈上:P)? Ctrl+Enter jQuery in TEXTAREA:
$('#textareaId').keydown(function (e) {
e = e || event; // for compatibility with IE (i belive)
if (e.ctrlKey && e.keyCode == 13) {
// Ctrl-Enter pressed
}
});
答案 2 :(得分:0)
为ExtJs 6工作(示例禁用Enter键):
Ext.create('Ext.form.HtmlEditor', {
width: 580,
height: 250,
renderTo: Ext.getBody(),
listeners:{
initialize: function(editor){
const doc = editor.getDoc();
const docEl = Ext.get(doc);
docEl.on({
keypress: (e)=>{
if (e.event.code === 'Enter'){
e.preventDefault();
}
},
delegated:false,
scope: editor
});
}
}
});