Sencha Touch 复选框字段具有带有长标签的时髦布局

发布于 2024-12-29 12:26:03 字数 336 浏览 2 评论 0原文

我的应用程序中的几个复选框字段有很长的标签,不幸的是它会导致一些奇怪的行为。

screenshot

有什么方法可以让它看起来更好一点吗?我的意思是,如果我“触摸”灰色区域,复选框不会激活(即使复选框位于灰色区域内)......但我必须单击白色区域。这有点令人困惑。

即使我为每个 checkboxfield 设置了 labelWidth: '80%',单词仍然会换行并显示那个小灰色区域。我希望该区域全部是白色的,并且所有区域都是“可触摸的”以激活复选框。

I've got long labels for a couple checkboxfields in my app, and unfortunately it causes some strange behavior.

screenshot

Is there any way to make this look a little better? I mean, if I 'touch' the gray area, the checkbox does not activate (even if the checkbox is inside the gray area)... but instead I have to click the white area. It's just kinda confusing.

Even if I set labelWidth: '80%' to each checkboxfield, the words still wrap and show that little gray area. I'd rather that area be all white and all of it be 'touchable' to activate the checkbox.

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

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

发布评论

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

评论(5

铁憨憨 2025-01-05 12:26:03

我也有同样的问题,我找到了3种方法来解决它,选择最适合你的方法,我使用第三个版本。抱歉,我的英语不是最好的,我希望它能被理解:(

第一个解决方案:
您可以添加自定义 css 条目。它可以解决问题,但如果您更改主题,则可能会出错。

.x-form-field-container {
    background: white;
}

第二个解决方案:
您可以使用溢出隐藏,但在这种情况下,末尾的文本将被剪切。

.x-form-label {
    overflow: hidden;
}

.x-form-label span
{
    white-space: nowrap;
}

第三种解决方案:

您可以在字段前使用 100% 宽度的标签。在这种情况下,输入字段的宽度也将是 100%。

new Ext.form.FormPanel({
    title: 'Form name',
    scroll: 'vertical',
    items: [{
        xtype: 'fieldset',
        title: 'Fieldset title',
        items: [{
            xtype: 'field',
            html: '<div class="x-form-label" style="width:100%"><span>This is the label of the field in below</span></div>'
        },{
            xtype: 'selectfield',
            name: 'nameOfTheField'
            //without label attribute
        }]
    }]
});

编辑

by rockinthesixstring

这是我为了达到相同的结果而进行的修改。

CSSJS

.x-checkbox{ background:white;}

{
    xtype: 'checkboxfield',
    name: 'updateinfo',
    label: 'Update my info',
    labelWidth: '80%',
    cls: "x-checkbox"
}

I have a same problem, I found 3 ways to fix it, choose the best way for you, I use the 3rd version. Sorry my english is not the best, I hope it will be understandable :(

1st solution:
You can add custom css entry. It will fix the problem, but if you change the theme, it could be wrong.

.x-form-field-container {
    background: white;
}

2nd solution:
You can use overflow hidden, but it this case the text on end will be cutted.

.x-form-label {
    overflow: hidden;
}

.x-form-label span
{
    white-space: nowrap;
}

3rd solution:

You can use your label with 100% width before the field. In this case the input field's width will 100% too.

new Ext.form.FormPanel({
    title: 'Form name',
    scroll: 'vertical',
    items: [{
        xtype: 'fieldset',
        title: 'Fieldset title',
        items: [{
            xtype: 'field',
            html: '<div class="x-form-label" style="width:100%"><span>This is the label of the field in below</span></div>'
        },{
            xtype: 'selectfield',
            name: 'nameOfTheField'
            //without label attribute
        }]
    }]
});

EDIT

by rockinthesixstring

Here's the modification that I made in order to achieve the same results.

CSS

.x-checkbox{ background:white;}

JS

{
    xtype: 'checkboxfield',
    name: 'updateinfo',
    label: 'Update my info',
    labelWidth: '80%',
    cls: "x-checkbox"
}
听你说爱我 2025-01-05 12:26:03

设置背景的问题在于您只是在显示级别上修复它。从功能上来说,输入元素仍然具有较小的高度。所以我们实际上需要拉伸输入元素的高度。

这是在我的案例中有效的修复方法。
添加 css 样式:

.x-form-label span {
    word-wrap: break-word; /*to avoid words that exceed length of the label*/
}

.x-input {
    /*
      the fix was working even without this, 
      but I'm leaving it here for more stability
    */
    position: relative;
}
.x-input input {
    /*basically, the main 4 magic lines of the fix*/
    position: absolute;
    height:100%;
    width: 70%;    
    right: 0;

    /*for more reliability*/
    top: 0;
    bottom: 0;
}

将 'x-input' 类分配给 Sencha 应用程序中的元素,如下所示:

new Ext.form.Radio({
    name: 'yourname',
    value: 'yourvalue',
    label: 'yourlabel',
    cls: 'x-input'
});

The problem in setting the background is that you're just fixing this on the display-level. Functionally, the input element will still have the small height. So we actually need to stretch the height of the input element.

Here's the fix that is working in my case.
Add css styles:

.x-form-label span {
    word-wrap: break-word; /*to avoid words that exceed length of the label*/
}

.x-input {
    /*
      the fix was working even without this, 
      but I'm leaving it here for more stability
    */
    position: relative;
}
.x-input input {
    /*basically, the main 4 magic lines of the fix*/
    position: absolute;
    height:100%;
    width: 70%;    
    right: 0;

    /*for more reliability*/
    top: 0;
    bottom: 0;
}

Assign 'x-input' class to the element in Sencha app, like this:

new Ext.form.Radio({
    name: 'yourname',
    value: 'yourvalue',
    label: 'yourlabel',
    cls: 'x-input'
});
甜警司 2025-01-05 12:26:03

这些答案实际上都没有使复选框区域的整个垂直空间可单击。您需要的是为包含的 div 指定固定高度,并为其所有子级指定 100% 高度(哦,好吧,如果您想深入研究并仅将其应用于您需要的 div,您可以这样做也是如此,但懒惰的方式效果很好)。这就是我的意思:

JS

{
    xtype: 'checkboxfield',
    id: 'YourIdHere',
    name : 'YourNameHere',
    label: 'Your Checkbox Label Here'
}

CSS

#YourIdHere {
    max-height: 50px !important;
    height: 50px !important;
}
#YourIdHere div {
    height:100% !important;
}

当然,如果您想要的话,这不会动态改变标签+复选框的高度。所以这不是一个完整的解决方案,但我敢打赌它在大多数情况下都能满足您的需求。这样做的原因是,当任何父 DIV 的高度未指定时,子 DIV 无法假定其父 DIV 的 100% 高度。您必须确保所有 DIV 都具有从 BODY 向下的高度,或者从具有固定高度的 DIV 向下的高度。

None of those answers actually makes the entire vertical space of the checkbox area clickable. What you'll need is to specify a fixed height for the containing div, and 100% height for all of its children (oh, well, if you want to dig in and only apply it to the divs you need, you can do that too, but the lazy way works fine). Here's what I mean:

JS

{
    xtype: 'checkboxfield',
    id: 'YourIdHere',
    name : 'YourNameHere',
    label: 'Your Checkbox Label Here'
}

CSS

#YourIdHere {
    max-height: 50px !important;
    height: 50px !important;
}
#YourIdHere div {
    height:100% !important;
}

Naturally, this won't dynamically change the height of the label + checkbox, if somehow you want that. So it's not a complete solution, but I'd wager it'll fit what you want in most cases. The reason why this works is because child DIVs cannot assume 100% height of their parent DIVs when any of their parents have unspecified height. You have to make sure all DIVs have a height from either the BODY on down, or from a DIV with a fixed height on down.

2025-01-05 12:26:03

当我遇到这个问题时,我设置了固定宽度(像素)和固定标签宽度(像素)。通常,调整标签宽度对我来说很有效。尝试使用固定宽度而不是百分比。

When I came across this issue I set a fixed width (pixels) and a fixed labelWidth (pixels). Usually just adjusting the label width worked for me though. Try using a fixed width instead of percent.

缘字诀 2025-01-05 12:26:03

您还可以在元素本身中添加样式

defaults: {
                    xtype: 'textfield',
                    required: true,
                    useClearIcon: true,
                    autoCapitalize: false,
                    style: 'font-size: 0.8em; background: white;',
                },

You can also add style in the element itself

defaults: {
                    xtype: 'textfield',
                    required: true,
                    useClearIcon: true,
                    autoCapitalize: false,
                    style: 'font-size: 0.8em; background: white;',
                },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文