简体   繁体   English

文本框处于焦点时的sencha显示工具提示

[英]sencha display tooltip of a text field when it is in focus

How do I display tooltip of a text field when it is in focus, not when mouse is hovering over? 当焦点对准文本字段时(而不是鼠标悬停时)如何显示工具提示?

I use TooltipConfig . 我使用TooltipConfig。

    TextField email = getEditor().getEmail();
    ToolTipConfig toolTipConfig = new ToolTipConfig();
    toolTipConfig.setBodyText("TEXT BODY");
    toolTipConfig.setAnchor(Style.Side.LEFT);
    toolTipConfig.setMouseOffsetY(0);
    toolTipConfig.setMouseOffsetX(0);

Are you using extjs? 您在使用extjs吗? If so, here's my answer: 如果是这样,这是我的答案:

You need to create custom tooltip to disable the default mouseover event. 您需要创建自定义工具提示以禁用默认的鼠标悬停事件。

 Ext.define('nutnull.ToolTip', function() { return { extend: 'Ext.tip.ToolTip', xtype: 'nutnull-tooltip', // Set this as emptyFn so that it will not create mouse event to show the tooltip setTarget: Ext.emptyFn }; }); 

Then you can override the textfield to show tooltip during focus event. 然后,您可以覆盖文本字段以在焦点事件期间显示工具提示。

 Ext.define('nutnull.override.Text', { override: 'Ext.form.field.Text', tip: null, onFocus: function() { // show tooltip if exist if(this.tip) { if(!this.tipCmp) { this.tipCmp = Ext.create('nutnull.ToolTip', { target: this.id, html: this.tip }); } // Get the position of the textfield instead of mouse position this.tipCmp.targetXY = this.getPosition(); // Adjust the position. this.tipCmp.targetXY[0] += this.getWidth(); this.tipCmp.targetXY[1] -= (this.getHeight()/2); // Manually show the tooltip this.tipCmp.show(); } this.callParent(arguments); } }); 

In the textfield item, just add tip: 'Sample Description' config. 在文本字段项中,只需添加tip: 'Sample Description'配置。

 { xtype: 'textfield', fieldLabel: 'Name', tip: 'Sample Description' } 

I resolved this problem. 我解决了这个问题。 I made new Tooltip object and wrapped tooltip config into this object. 我制作了新的工具提示对象,并将工具提示配置包装到该对象中。

TextField email = getEditor().getEmail();
ToolTipConfig toolTipConfig = new ToolTipConfig();
toolTipConfig.setBodyText("TEXT BODY");
toolTipConfig.setAnchor(Style.Side.LEFT);
toolTipConfig.setMouseOffsetY(0);
toolTipConfig.setMouseOffsetX(0);
Tooltip tooltip = new ToolTip(email,toolTipConfig);
tooltip.show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM