我怎样才能让这个字段集边框紧紧包裹住它的内容

发布于 2024-10-04 05:23:40 字数 1185 浏览 1 评论 0原文

我有一个带有动态添加字段(大小不同)的表单。 我想将多个表单字段放入字段集中,并使字段集边框足够大以包含所有字段。

这是一个显示问题的(丑陋的)示例:

var win = new Ext.Window({
    xtype: 'form',
    layout: 'form',
    height: 200,
    width: 500,
    title: 'Testing',
    items: [{
        xtype: 'fieldset',
        layout: 'hbox',
        autoHeight:true,
        autoWidth: false,
        title: 'Fieldset',
        defaults: {
            border: false,
            layout: 'form',
            labelAlign: 'top',
            labelSeparator: ''
        },
        items: [{
            items: new Ext.form.TextField({
                fieldLabel: 'Col1',
                name: 'col1',
                value: 'nothing',
            })
        }, {
            items: new Ext.form.TextField({
                fieldLabel: 'Col2',
                name: 'col2',
                value: 'something'
            })
        }]
    }, 
        new Ext.form.TextField({
            fieldLabel: 'Col3',
            name: 'col3',
            value: 'anything'
        })
    ]
}).show();

这就是它的样子: alt text

我会事先不知道所包含字段的宽度,因此我无法指定宽度。

感谢您的任何建议。

I have a form with dynamically added fields (varying sizes).
I would like to put a number of form fields in a fieldset, and have the fieldset border just large enough to contain all the fields.

Here is an (ugly) example that shows the issue:

var win = new Ext.Window({
    xtype: 'form',
    layout: 'form',
    height: 200,
    width: 500,
    title: 'Testing',
    items: [{
        xtype: 'fieldset',
        layout: 'hbox',
        autoHeight:true,
        autoWidth: false,
        title: 'Fieldset',
        defaults: {
            border: false,
            layout: 'form',
            labelAlign: 'top',
            labelSeparator: ''
        },
        items: [{
            items: new Ext.form.TextField({
                fieldLabel: 'Col1',
                name: 'col1',
                value: 'nothing',
            })
        }, {
            items: new Ext.form.TextField({
                fieldLabel: 'Col2',
                name: 'col2',
                value: 'something'
            })
        }]
    }, 
        new Ext.form.TextField({
            fieldLabel: 'Col3',
            name: 'col3',
            value: 'anything'
        })
    ]
}).show();

This is what it looks like: alt text

I will not know the width of the contained fields beforehand, so I can't specify a width.

Thanks for any suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只有一腔孤勇 2024-10-11 05:23:40

不是您所要求的,但将 flex: 1 添加到字段集的默认值会使字段在字段集的范围内均匀排列。

Not what you asked for, but adding flex: 1 to the defaults for the fieldset makes the fields arrange themselves evenly within the bounds of the fieldset.

恋你朝朝暮暮 2024-10-11 05:23:40

好的,可以通过更改一些字段集属性来实现:
布局到“表格”,
autoWidth 为 true,
添加带有“float:left”的 cls,(将其放入样式中似乎没有帮助)
并添加一个虚拟元素来清除浮动:
{
xtype: '组件',
风格:'明确:两者'

现在它按需要显示了

Ok, works by changing some fieldset properties:
layout to 'table',
autoWidth to true,
adding a cls with 'float:left', (putting this in style doesn't seem to help)
and adding a dummy element to clear the float:
{
xtype: 'component',
style: 'clear:both'
}

It now shows as desired!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文