31

自从升级到 ExtJS 4.2 以来,我注意到当文本字段中有错误时显示的工具提示不够宽,无法看到工具提示的内容——它们似乎总是 40px 宽。

这是一个显示问题的测试用例:

<html>
<head>
    <title>Field error tooltips</title>
    <link rel="stylesheet" type="text/css" href="ext-4.2.0/resources/css/ext-all.css">
    <script type="text/javascript" src="ext-4.2.0/ext-all-debug.js"></script>
</head>
<body>
    <script type="text/javascript">
    Ext.onReady(function(){

        var form = Ext.create("Ext.form.Panel",{
            title: 'My form',
            width: 300,
            height: 100,
            items: [
                {xtype: 'textfield', name: 'FIELD1', fieldLabel: 'Field 1', allowBlank: false}
            ],
            renderTo: Ext.getBody()
        });
    });
    </script>
</body>
</html>

在上面的示例中,如果您单击该字段,然后在没有输入任何内容的情况下单击它,它会显示一个工具提示,说明它不允许为空。不幸的是,工具提示不够宽,无法看到该消息。有没有其他人遇到过这个?

谢谢!

4

9 回答 9

28

感谢大家的帮助,但我在 sencha 论坛上找到了一个似乎可行的解决方案:

http://www.sencha.com/forum/showthread.php?260106-Tooltips-on-forms-and-grid-are-not-resizing-to-the-size-of-the-text/page3#24

特别是应用程序开头的以下代码:

delete Ext.tip.Tip.prototype.minWidth;
于 2013-04-08T13:22:26.497 回答
17

这是 extjs 4.2 的错误,它适用于 firefox 19 但不适用于 chrome 26

您应该覆盖工具提示的 css 类:

.x-tip {
    width: auto !important;
}
.x-tip-body {
    width: auto !important;
}
.x-tip-body span {
    width: auto !important;
}
于 2013-04-08T01:44:02.600 回答
4

抱歉,我帮不上什么忙,这是 4.2.0 的一个已知问题,可能会在下一个版本中修复。见:http ://www.sencha.com/forum/showthread.php?257201

作为临时解决方法,如果您不需要提示容器的动态大小,您可以覆盖 CSS

.x-tip-form-invalid, .x-tip-body-form-invalid {
    width: 150px !important;
}
于 2013-04-06T02:19:58.867 回答
3

出于好奇,时不时地看这个……

我尝试比较 4.1 和 4.2 的来源。我认为问题出在某个地方的自动容器布局中。在 4.1 和 4.2 之间发生了很多变化。所以我们可以看看这个。

希望它适用于某些人。

if(Ext.isIE10) { 
      Ext.supports.Direct2DBug = true;
  }

  if(Ext.isChrome) {
      Ext.define('Ext.layout.container.AutoTip', {
        alias: ['layout.autotip'],
        extend: 'Ext.layout.container.Container',

        childEls: [
            'clearEl'
        ],

        renderTpl: [
            '{%this.renderBody(out,values)%}',

            '<div id="{ownerId}-clearEl" class="', Ext.baseCSSPrefix, 'clear" role="presentation"></div>'
        ],

        calculate: function(ownerContext) {
            var me = this,
                containerSize;

            if (!ownerContext.hasDomProp('containerChildrenDone')) {
                me.done = false;
            } else {

                containerSize = me.getContainerSize(ownerContext);
                if (!containerSize.gotAll) {
                    me.done = false;
                }

                me.calculateContentSize(ownerContext);
            }
        }
    });

    Ext.override(Ext.tip.Tip, {
        layout: {
            type: 'autotip'
        }
    });
}

Ext.QuickTips.init();

您可以查看有关此论坛主题的更多详细信息。

于 2013-04-10T10:42:00.227 回答
3

删除 Ext.tip.Tip.prototype.minWidth 并不能在所有情况下(在 IE10 上)为我解决问题,并添加

if(Ext.isIE10) { 
      Ext.supports.Direct2DBug = true;
}

修复了工具提示,但会导致其他奇怪的问题(有时会影响工具栏按钮的边距!)。我见过的最好的解决方案是:

Ext.override(Ext.tip.QuickTip, {
        helperElId: 'ext-quicktips-tip-helper',
        initComponent: function ()
        {
            var me = this;


            me.target = me.target || Ext.getDoc();
            me.targets = me.targets || {};
            me.callParent();


            // new stuff
            me.on('move', function ()
            {
                var offset = me.hasCls('x-tip-form-invalid') ? 35 : 12,
                    helperEl = Ext.fly(me.helperElId) || Ext.fly(
                        Ext.DomHelper.createDom({
                            tag: 'div',
                            id: me.helperElId,
                            style: {
                                position: 'absolute',
                                left: '-1000px',
                                top: '-1000px',
                                'font-size': '12px',
                                'font-family': 'tahoma, arial, verdana, sans-serif'
                            }
                        }, Ext.getBody())
                    );

                if (me.html && (me.html !== helperEl.getHTML() || me.getWidth() !== (helperEl.dom.clientWidth + offset)))
                {
                    helperEl.update(me.html);
                    me.setWidth(Ext.Number.constrain(helperEl.dom.clientWidth + offset, me.minWidth, me.maxWidth));
                }
            }, this);
        }
    });

这似乎适用于 IE9 和 10、Chrome 和 Firefox。

于 2013-04-25T16:37:14.913 回答
0

另一个不错的解决方案是添加这个 CSS :

.x-border-box .x-tip, .x-border-box .x-tip * {
  box-sizing: content-box;
}

但是工具提示有点太大了。

我将尝试使用覆盖 Ext.tip.QuickTip 的 user826840 的解决方案。

于 2014-09-11T13:19:58.383 回答
0

另一种解决方案是覆盖 QuickTip 的最小宽度,因为字段布局会创建不依赖 QuickTip 单例的新 QuickTip(与文档相反)。

Ext.override(Ext.tip.QuickTip,{
    minWidth: 200
});
于 2016-02-19T13:26:29.027 回答
0

使用<br/>标签显示多行工具提示有时对解决宽度问题很有用。

const msg = 'bla bla...<br/>bla bla...'; // Here <br/> tag in html message.

Ext.create('Ext.tip.ToolTip', {
    target: component.id,
    html: msg
});
于 2020-10-09T10:17:24.117 回答
-1

如果您在 IE 浏览器中遇到工具提示 EXTJS 4.2.1 的问题。您必须将以下行添加到您的 ASPX 页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
于 2014-04-25T09:41:20.473 回答