单击文本框时动态显示消息

时间:2013-04-25 12:35:57

标签: extjs textbox extjs4 onclicklistener keylistener

如何在单击文本字段时动态显示消息/具有任何值,并且当我删除文本字段的内容时消息必须消失

2 个答案:

答案 0 :(得分:0)

您可以在文本字段中使用侦听器。我没有测试过以下代码,但你可以尝试类似的东西。

{
    xtype: 'textfield',
    messageTip: undefined,
    listeners: {
        afterrender: function(text) { //Textfield doesn't have a click even't so use afterrender to put a click event on the element
            //U can use text.inputEl.on({ aswell to only get the input element and not the label
            text.getEl().on({
                click: function() {
                     //Create tip here
                     text.messageTip = Ext.create('Ext.tip.Tip', {
                         //Configuration
                     }).show();
                }
            });
        },
        keypress: function(text) {
            if (text.getValue() == '') {
                //hide the message
                text.messageTip.hide()
            }
        }
    }
}

答案 1 :(得分:0)

您可以在文本字段中使用“更改”侦听器:

{
    xtype: 'textfield',
    listeners : {
        change: function(field, newValue, oldValue, options)) {
                   if(newvalue!=''){
                       Message=Ext.create('Ext.tip.ToolTip', {
                       closable:true,
                       hideDelay : 3000,
                       padding: '0 0 0 0',
                       maxWidth:400,
                       width:800,
                       html: ".......",
                      }).showAt([x, y]); 
                        }
                  else Message.hide();
                    }
                }
}
相关问题