No Code Attached Yet
avatar rogercreagh
rogercreagh
6 Feb 2025

Steps to reproduce the issue

Create subforms using repeatable -table with 1,2,3 and more columns and including or not the hidden listorder fcolumn (eg lisorder column is usually hidden if drag and drop reordering is enabled)

Expected result

Columns should divide available width between them - given there is no class attribute available for subform fields they should have equal widths apart except for any hidden fields which should not occupy space (or a minimal couple of pixels)

Actual result

For 2 columns with no hidden column they are each given 45% with the controls on the right being allowed 8%

In all other cases all of the columns (including any hidden ones) are given style="width:45%;"hardcoded in the layout file in the <thead><tr><th ...>elements. This results in silly layouts with fields of more or less arbitrary width depending on browser including hidden ones taking up space.

System information (as much as possible)

Joomla 5.2.3 any browser (tested with Edge), any server (tested on Apache Ubuntu 24.04)

Additional comments

Why oh why is the hardcoded style present in

/layouts/joomla/form/field/subform/repeatable-table.php

The repeatable table layout hardcodes a style="width:45%" for all columns in the table in the irrespective how many columns there are. It is ok for two columns but is silly with one column or more than 2 in the table. It also doesn't take account of any hidden columns (eg "listorder") and assigns 45% width for them too which result in blank space at the right of the row.

Simple fix is to count the number of columns excluding hidden ones before iterating through them in the thead section of the layout and assign an equal percentage to each adding up to 92% or less (8% for controls)

Best would be to simply remove the hardcoded style and allow a class attribute for each column in the field specification which would allow the designer to specify the relative widths she wanted.

Additional additional comment - while we are here on wide screens there is a problem in that for text type fields the actual box may not use all the available space - it works better if for text and url (and similar) fields the control width is set to 100%.

These problems are fairly easily overcome using a layout override, but they are silly errors in core Joomla which should be fixed.

Yes you can fix it yourself by making a layout override, but it is a silly error in the core code which should be fixed. (not my pay grade, I develop components and don't mess with core code)

avatar rogercreagh rogercreagh - open - 6 Feb 2025
avatar joomla-cms-bot joomla-cms-bot - change - 6 Feb 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 6 Feb 2025
avatar rogercreagh
rogercreagh - comment - 6 Feb 2025

Here's some sample code to replace lines 62-71 in the current repeatable-table.php

} else {
    $cnt=0;
    foreach ($tmpl->getGroup('') as $field) {
        if (strip_tags($field->type) != 'Hidden') $cnt ++;
    }
    $wid = intdiv(92, $cnt);
    foreach ($tmpl->getGroup('') as $field) {
        //  Factory::getApplication()->enqueueMessage(print_r(strip_tags($field->type),true));
        $table_head .= '<th scope="col" ';
        if (strip_tags($field->type) == 'Hidden') {
            $table_head .= 'style="display:none;">';
        } else {
            $table_head .= 'style="width:'.$wid.'%">' . strip_tags($field->label);
        }        
        if ($field->description) {
            $table_head .= '<span class="icon-info-circle" aria-hidden="true" tabindex="0"></span><div role="tooltip" id="tip-' . $field->id . '">' . Text::_($field->description) . '</div>';
        }       
        $table_head .= '</th>';
    }

then you also need a fix for the hidden fields in the table body which is set in subform/repeatable-table/section.php where the td elements get added around line 30 replace with

        <td data-column="<?php echo strip_tags($field->label); ?>"
                <?php if (strip_tags($field->type) == 'Hidden') echo 'style="display:none;" '; ?>
        >

To fix the constrained width of text boxes you can use some css

joomla-field-subform .table td input[type="text"],
joomla-field-subform .table td input[type="url"] ,
joomla-field-subform .table td input[type="search"] ,
joomla-field-subform .table td input[type="tel"] {
	width:100%;
}

These examples taken from the layout override that I use - it works for me in my components. There maybe better ways of doing it, or more correct Joomla ways of doing it, so this needs proper checking and testing before implementation - not something I can do, but a starter for someone who can.

avatar chmst
chmst - comment - 7 Feb 2025

issue confirmed.
@rogercreagh as you have a solution, would you like to make a PR? Then it can be tested and discussed.

avatar Fedik
Fedik - comment - 7 Feb 2025

That is expected behavior, for hidden field in the table. Kind of.
Use groupByFieldset or use non table layout, when you want hidden field in the subform table layout.

avatar rogercreagh
rogercreagh - comment - 7 Feb 2025

That is expected behavior, for hidden field in the table. Kind of. Use groupByFieldset or use non table layout, when you want hidden field in the subform table layout.

Confused I am.
I want to use table layout cos it works well and I need to include hidden field(s), group by fieldset doesn't cut it, A hidden field surely should be hidden and NOT take up space in the layout.

Anyway that is only part of the problem - more important is the weird fields widths. While fixing that there is no harm in making hidden fields properly hidden (except for the td padding which has to be fixed by css separately if you don't like it (I dont but its not a big deal)

I don't propose to submit a css change to fix the unwanted padding on hidden fields or the text boxes not being full width of the cells - if it bugs you it is easy enough to fix with component or template css

avatar rogercreagh
rogercreagh - comment - 7 Feb 2025

issue confirmed. @rogercreagh as you have a solution, would you like to make a PR? Then it can be tested and discussed.

Okay, but it'll get rejected cos I don't have a core Joomla development setup and so can't run unit tests or any of that stuff. I' could simply lie and declare I have tested it. Someone else will have to actually do the testing.

avatar QuyTon
QuyTon - comment - 8 Feb 2025

@rogercreagh Please consider testing #42347. Thanks.

Add a Comment

Login with GitHub to post a comment