【问题标题】:Fieldcontainer incorrectly displays in toolbar with label aligned topFieldcontainer 错误地显示在工具栏中,标签对齐顶部
【发布时间】:2016-06-16 10:23:28
【问题描述】:

当您放置 labelAlign: 'top' 时,FieldContainer 无法正确显示。

找到我的小提琴:https://fiddle.sencha.com/#fiddle/1c2s 我创建了一个基于字段容器的自定义字段。 如果将窗口调整为更小的尺寸,您会看到文本字段将位于 fieldContiner 上方。

关于如何解决这个问题的任何想法?任何解决方法? 我已经尝试了几种方法,但我很挣扎……我现在无法采取行动来改变这一点…… 我肯定需要解决这个问题。

提前致谢

(供参考:在煎茶论坛打开bug:https://www.sencha.com/forum/showthread.php?311212-Fieldcontainer-incorrectly-displays-in-toolbar-with-label-aligned-top

【问题讨论】:

  • 我记得我早些时候报告了这个错误(2014 年?)。 IIRC 我当时没有找到完整的解决方法,但删除了 vbox 布局,这起到了作用。
  • 是的...这将是一个“简单”的解决方案,但如何才能替代它呢?什么? (顺便说一下,这是hbox 而不是vbox)。如果我将容器中的vbox 更改为form,则不会考虑labelAlign: 'top'
  • 如果您在小提琴中搜索vbox(而不是hbox!)并删除您找到的布局,您会发现,通过纯粹的魔法,labelAlign 已正确应用。但是你必须找到另一种方法来获得像align:'stretch' 这样的东西,layout:'auto' 不支持。
  • 也就是说,我认为 Sencha 不确定该错误是否与 fieldcontainer 或框布局有关,这就是为什么没人关心(两个代码所有者都说“我的代码是干净的”并等待另一个一个来收拾烂摊子)。
  • 好的,知道了。但是,是的……align:'stretch' 需要别的东西。我试试看

标签: extjs extjs6 extjs6-classic


【解决方案1】:

看起来确实像错误,但有一种很简单的方法可以让它工作 - 只需将 minHeight: 65 设置为您的 url 字段。

小提琴:https://fiddle.sencha.com/#fiddle/1caa

【讨论】:

  • 感谢@krysztof 提供此解决方法。但是,对于更宽的用例来说,这是一个简单的案例……我有 FieldContainer,它要复杂得多,并且高度可以改变(根据用户操作)。而且我现在不知道如何处理...
  • 大小调整似乎有效,所以唯一的问题是将height 复制到minHeight。例如,您可以使用 renderresize 处理程序来执行此操作。查看更新的小提琴:fiddle.sencha.com/#fiddle/1caa
  • 你的解决方案工作......很好。这并不完美。我有一些隐藏/显示面板的 FieldContainer,如果它显示某些内容并随后隐藏,则大小计算得不好,大小保持“大”。另一方面,我注意到这似乎不是使用的正确组件布局!如果你用Ext.getCmp取字段容器,转到componentLayout.calculateOwnerHeightFromContentHeight你会看到它指向了auto的布局方法……在我看来,这就是原因……
【解决方案2】:

我很确定我找到了答案。 build src 和 doc 不匹配!

如果您检查文件src/layout/component/field/FieldContainer.js 的构建源代码,您会注意到它与文档不对应(尤其是缺少一些方法,例如calculateOwnerHeightFromContentHeight)。

注意:这已在 ExtJs 6.2.0 中修复

建议覆盖以解决此问题:

/**
 * Override to fix componentLayout wrong calculation of height when labelAlign='top'
 *
 * See post forum:
 * {@link https://www.sencha.com/forum/showthread.php?311212-Fieldcontainer-incorrectly-displays-in-toolbar-with-label-aligned-top}
 */
Ext.define('MyApp.overrides.layout.component.field.FieldContainer', {
    override: 'Ext.layout.component.field.FieldContainer',
    compatibility: [
        '6.0.0',
        '6.0.1',
        '6.0.2'
    ],

    /* Begin Definitions */

    calculateOwnerHeightFromContentHeight: function(ownerContext, contentHeight) {
        var h = this.callSuper([ownerContext, contentHeight]);
        return h + this.getHeightAdjustment();
    },

    calculateOwnerWidthFromContentWidth: function(ownerContext, contentWidth) {
        var w = this.callSuper([ownerContext, contentWidth]);
        return w + this.getWidthAdjustment();
    },

    measureContentHeight: function(ownerContext) {
        // since we are measuring the outer el, we have to wait for whatever is in our
        // container to be flushed to the DOM... especially for things like box layouts
        // that size the innerCt since that is all that will contribute to our size!
        return ownerContext.hasDomProp('containerLayoutDone') ? this.callSuper([ownerContext]) : NaN;
    },

    measureContentWidth: function(ownerContext) {
        // see measureContentHeight
        return ownerContext.hasDomProp('containerLayoutDone') ? this.callSuper([ownerContext]) : NaN;
    },

    publishInnerHeight: function(ownerContext, height) {
        height -= this.getHeightAdjustment();
        ownerContext.containerElContext.setHeight(height);
    },


    publishInnerWidth: function(ownerContext, width) {
        width -= this.getWidthAdjustment();
        ownerContext.containerElContext.setWidth(width);
    },

    privates: {
        getHeightAdjustment: function() {
            var owner = this.owner,
                h = 0;

            if (owner.labelAlign === 'top' && owner.hasVisibleLabel()) {
                h += owner.labelEl.getHeight();
            }

            if (owner.msgTarget === 'under' && owner.hasActiveError()) {
                h += owner.errorWrapEl.getHeight();
            }

            return h + owner.bodyEl.getPadding('tb');
        },

        getWidthAdjustment: function() {
            var owner = this.owner,
                w = 0;

            if (owner.labelAlign !== 'top' && owner.hasVisibleLabel()) {
                w += (owner.labelWidth + (owner.labelPad || 0));
            }

            if (owner.msgTarget === 'side' && owner.hasActiveError()) {
                w += owner.errorWrapEl.getWidth();
            }

            return w + owner.bodyEl.getPadding('lr');
        }
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    相关资源
    最近更新 更多