Custom form template for repeating groups

Dear All,

It would be great if someone could point me to right file and text line where to start and insert the elements to generate a custom form template for repeated groups?
I know how to insert them but i am just to new to the farbik backend code that i would be grateful if someone just could give me a little hint where to start.

There is already and example from hugh in the forum but this is related to an old version of fabrik in which the structure of the template files is a little diffrent.
 
Look at this files in your selected form template.
default_repeatgroup.php
default_repeatgroup_row.php
default_repeatgroup_table.php
 
There really isn't any guides or tutorials on doing that.

Which repeat template are you wanting to customize? The table layout or the normal div layout?

-- hugh
 
Actually the table layout. a starting point where and how to place the elements in the repeated group would be great.
I have too many elements in my form and i need to place them correctly.
Howver if the table layout is too complicted i could switch to the standard div layout.
 
Doesn't make much difference to the complexity.

Basically, you'll have to extract some of the code from default_repeatgroup_row.php, everything between ...

PHP:
<?php foreach ($this->elements as $element) :
// everything in this foreach ...
    endforeach;

... and insert it into a new file, something like default_repeatgroup_row_element.php. Prepend this to the start of the new file:

PHP:
defined('_JEXEC') or die('Restricted access');

$element = $this->element;

So you now have a separate template file which builds the TD for each element.

Then in default_repeatgroup_row.php, instead of that foreach, you can then render each element individually, by doing ...

Code:
$this->element = $this->elements['element_name'];
echo $this->loadTemplate('repeatgroup_row_element');

So, say you had four elements, named field1 through field4, and you wanted to render them in two rows inside the normal one row, you could do something like ...

PHP:
<?php
/**
* Default Form: Repeat group rendered as a table, <tr> template
*
* @package     Joomla
* @subpackage  Fabrik
* @copyright   Copyright (C) 2005-2016  Media A-Team, Inc. - All rights reserved.
* @license     GNU/GPL http://www.gnu.org/copyleft/gpl.html
* @since       3.0
*/

// No direct access
defined('_JEXEC') or die('Restricted access');

$group = $this->group;
?>
<tr class="fabrikSubGroupElements fabrikSubGroup">
<td>
    <table>
        <tr>
           <td>
              <?php
              $this->element = $this->elements['field1'];
              echo $this->loadTemplate('repeatgroup_row_element');
              ?>
          </td>
          <td>
             <?php
             $this->element = $this->elements['field2'];
             echo $this->loadTemplate('repeatgroup_row_element');
             ?>
         </td>
        </tr>
        <tr>
            <td>
                <?php
                $this->element = $this->elements['field3'];
                echo $this->loadTemplate('repeatgroup_row_element');
                ?>
            </td>
           <td>
               <?php
               $this->element = $this->elements['field4'];
               echo $this->loadTemplate('repeatgroup_row_element');
               ?>
          </td>
        </tr>
    </table>
</td>
<?php
    if ($group->editable) : ?>
        <td class="fabrikGroupRepeater">
            <div class="pull-right">
            <?php
            if ($group->canAddRepeat) :
                echo $this->addRepeatGroupButtonRow;
            endif;
            if ($group->canDeleteRepeat) :
                echo $this->removeRepeatGroupButtonRow;
            endif;
            ?>
            </div>
        </td>
    <?php endif; ?>
</tr>

... so basically we've replaced the 'foreach' that renders each element, with a specific two row table layout the individually renders four elements.

-- hugh
 
My Code below it actually gives me two rows however it displays all elements in each row:

default_repeatgroup_row :
PHP:
<?php
/**
* Default Form: Repeat group rendered as a table, <tr> template
*
* @package     Joomla
* @subpackage  Fabrik
* @copyright   Copyright (C) 2005-2016  Media A-Team, Inc. - All rights reserved.
* @license     GNU/GPL http://www.gnu.org/copyleft/gpl.html
* @since       3.0
*/

// No direct access
defined('_JEXEC') or die('Restricted access');

$group = $this->group;
?>
<tr class="fabrikSubGroupElements fabrikSubGroup">
<td>
    <table>
        <tr>
           <td>
              <?php
              $this->element = $this->elements['od'];
              echo $this->loadTemplate('repeatgroup_row_element');
              ?>
          </td>
          <td>
             <?php
             $this->element = $this->elements['ppf'];
             echo $this->loadTemplate('repeatgroup_row_element');
             ?>
         </td>
        </tr>
        <tr>
            <td>
                <?php
                $this->element = $this->elements['grade'];
                echo $this->loadTemplate('repeatgroup_row_element');
                ?>
            </td>
           <td>
               <?php
               $this->element = $this->elements['connection'];
               echo $this->loadTemplate('repeatgroup_row_element');
               ?>
          </td>
        </tr>
    </table>
</td>
<?php
    if ($group->editable) : ?>
        <td class="fabrikGroupRepeater">
            <div class="pull-right">
            <?php
            if ($group->canAddRepeat) :
                echo $this->addRepeatGroupButtonRow;
            endif;
            if ($group->canDeleteRepeat) :
                echo $this->removeRepeatGroupButtonRow;
            endif;
            ?>
            </div>
        </td>
    <?php endif; ?>
</tr>


default_repeatgroup_row_element :

PHP:
<?php
/**
* Default Form: Repeat group rendered as a table, <tr> template
*
* @package     Joomla
* @subpackage  Fabrik
* @copyright   Copyright (C) 2005-2016  Media A-Team, Inc. - All rights reserved.
* @license     GNU/GPL http://www.gnu.org/copyleft/gpl.html
* @since       3.0
*/

// No direct access
defined('_JEXEC') or die('Restricted access');

$element = $this->element;
?>

<?php foreach ($this->elements as $element) :
    $style = $element->hidden ? 'style="display:none"' : '';
    ?>
    <td class="<?php echo $element->containerClass; ?>" <?php echo $style?>>
    <?php
    if ($this->tipLocation == 'above') :
    ?>
        <div><?php echo $element->tipAbove; ?></div>
    <?php
    endif;
    echo $element->errorTag; ?>
    <div class="fabrikElement">
        <?php echo $element->element; ?>
    </div>

    <?php if ($this->tipLocation == 'side') :
        echo $element->tipSide;
    endif;
    if ($this->tipLocation == 'below') : ?>
        <div>
            <?php echo $element->tipBelow; ?>
        </div>
    <?php endif;
    ?>
    </td>
    <?php
    endforeach;

Anything i did wrong?
 
Yes. Not at computer atm, so can't edit the code, but you'll need to replace the foreach that iterates through $firstGroup with something similar to your row code, which lays out individual $firstGroup['fieldname'].

Sent from my HTC 10 using Tapatalk
 
In repeatgroup_table ... replace this:

PHP:
    // Add in the table heading
    $firstGroup = $group->subgroups[0];
    foreach ($firstGroup as $el) :
        $style = $el->hidden ? 'style="display:none"' : '';
        ?>
        <th <?php echo $style; ?> class="<?php echo $el->containerClass?>">
            <?php echo $el->label_raw?>
        </th>
        <?php
    endforeach;

... with something like ...

PHP:
    $firstGroup = $group->subgroups[0];
    ?>
    <table>
        <tr>
            <th class="<?php echo $firstGroup['field1']->containerClass?>">
                <?php echo $firstGroup['field1']->label_raw?>
            </th>
            <th class="<?php echo $firstGroup['field2']->containerClass?>">
                <?php echo $firstGroup['field2']->label_raw?>
            </th>
        </tr>
        <tr>
            <th class="<?php echo $firstGroup['field3']->containerClass?>">
                <?php echo $firstGroup['field3']->label_raw?>
            </th>
            <th class="<?php echo $firstGroup['field4']->containerClass?>">
                <?php echo $firstGroup['field4']->label_raw?>
            </th>
        </tr>
    </table>
    <?php

... to match whatever layout you have in the row.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top