簡體   English   中英

ExtJS 4.2:工具提示不夠寬,無法看到內容

[英]ExtJS 4.2: ToolTips not wide enough to see contents

自從升級到 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>

在上面的示例中,如果您單擊該字段,然后在不輸入任何內容的情況下單擊它,它會顯示一個工具提示,說明它不允許為空。 不幸的是,工具提示不夠寬,無法看到消息。 有沒有其他人遇到過這個?

謝謝!

感謝您的幫助,但我在 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;

這是 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;
}

抱歉,我幫不上什么忙,這是 4.2.0 的一個已知問題,可能會在下一個版本中修復。 參見: http : //www.sencha.com/forum/showthread.php?257201

作為臨時解決方法,如果您不需要動態調整提示容器的大小,您可以只覆蓋 CSS

.x-tip-form-invalid, .x-tip-body-form-invalid {
    width: 150px !important;
}

出於好奇,仍然時不時地看着這個......

我嘗試更多地比較 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();

您可以查看有關此論壇主題的更多詳細信息。

對我來說,刪除 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。

另一個不錯的解決方案是添加這個 CSS:

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

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

我將嘗試覆蓋 Ext.tip.QuickTip 的 user826840 的解決方案。

另一種解決方案是覆蓋 QuickTip 的最小寬度,因為字段布局創建了不依賴於 QuickTip 單例的新 QuickTip(與文檔相反)。

Ext.override(Ext.tip.QuickTip,{
    minWidth: 200
});

使用<br/>標簽顯示多行工具提示有時對解決寬度問題很有用。

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

Ext.create('Ext.tip.ToolTip', {
    target: component.id,
    html: msg
});

如果您在 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">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM