[Solved] Condition the display of repeated groups according to a field

georgie

Member
Hello

I would to limit the display of a repeated group according to a field.
I mean to hide each row from a group repeatable if his field is equal to "0" for example.

Can I do this in the form template?

Georges
 
You can use javascript on-load and on-change events to hide the elements. That means that they are in the HTML if someone sufficiently knowledgeable wants to look, but they are not visible in the web page.
 
Héhé

Thank you, but it is not exactly I would.
Javascript rules go to hide all the group or only element. But me I want to hide rows related only.

It is something like Prefilters in list, but I can not use Prefilters in my main list, because it hide records when just one row is related.

No, I think I have to do this in PHP in my form template, or creating a list pointing on my subgroup (and then prefilter on this sublist).
But I would prefer do this in PHP in my form template.

Georges
 
You could do it in a custom template, editing default_repeatgroup.php, around line 21 at the start of the foreach. Test your element's value, and just 'continue' if it is 0 ...

Code:
if ($subgroup['yourfield']->value === '0'):
   continue;
endif;

-- hugh
 
Hello

Thank you for your help, indeed I would do it in a custom template.
But it does not work as it, or maybe I do a mistake.

I try this, but with no effect:

PHP:
<?php

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

$input = JFactory::getApplication()->input;
$group = $this->group;
$i = 1;
$w = new FabrikWorker;

foreach ($group->subgroups as $subgroup) :

// ADD TEST
if ($subgroup['commande___DUE_TTC_raw']->value === '0.00'):
continue ;
endif ;

    $introData = array_merge($input->getArray(), array('i' => $i));
    ?>
    <div class="fabrikSubGroup">
        <div data-role="group-repeat-intro">
            <?php echo $w->parseMessageForPlaceHolder($group->repeatIntro, $introData);?>
        </div>
    <?php
        // Add the add/remove repeat group buttons
        if ($group->editable && ($group->canAddRepeat || $group->canDeleteRepeat)) : ?>
            <div class="fabrikGroupRepeater pull-right btn-group">
                <?php if ($group->canAddRepeat) :
                    echo $this->addRepeatGroupButton;
                endif;
                if ($group->canDeleteRepeat) :
                    echo $this->removeRepeatGroupButton;
                endif;?>
            </div>
        <?php
        endif;
        ?>
        <div class="fabrikSubGroupElements">
            <?php

            // Load each group in a <ul>
            $this->elements = $subgroup;
            echo $this->loadTemplate('group');
            ?>
        </div><!-- end fabrikSubGroupElements -->
    </div><!-- end fabrikSubGroup -->
    <?php
    $i ++;

endforeach;

Also I do not understand how my template knows in what subgroups to work, only by the field?
Indeed I have several subgroups in my form, and also the subgroup concerned is in "Read only".

Georges
 
Don't use the _raw suffix, that won't exist.

Try something like this ...

Code:
if (array_key_exists('commande___DUE_TTC', $subgroup)):
   //var_dump($subgroup['commande___DUE_TTC']);
   if ($subgroup['commande___DUE_TTC']->value === '0.00'):
      continue ;
   endif;
endif;

If it doesn't work, uncomment the var_dump() and see if that outputs anything.

-- hugh
 
Thanks, I understand better (a little bit...).

But it does not work for now, no bug but no effect.

Uncommenting var_dump does not display anything, no bug but no effect.

I note I can do a var_dump like this:
Code:
$My_Var = $this->getModel()->getElementData('commande___DUE_TTC', true) ;
var_dump($My_Var) ;

This display a correct array, but not in the good subgroup. The array is displayed in my other subgroups.

Please have you an idea with theses new details?

Georges
 
Oh, sorry, at that point it's using short element names, so just change commande___DUE_TTC to DUE_TTC. Hopefully you don't use the same name in a different group.

-- hugh
 
Thank you but no change...

Also I can not do a dump, so I do not undertand.

Note my DUE_TTC field use a format string (%s €). It is not a problem?

Please see my actual code (no bug but no change):

Code:
<?php

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

$input = JFactory::getApplication()->input;
$group = $this->group;
$i = 1;
$w = new FabrikWorker;

foreach ($group->subgroups as $subgroup) :

// ADD TEST
if (array_key_exists('DUE_TTC', $subgroup)):
   // var_dump($subgroup['DUE_TTC']);
   if ($subgroup['DUE_TTC']->value === '0'):
      continue ;
   endif;
endif;

    $introData = array_merge($input->getArray(), array('i' => $i));
    ?>
    <div class="fabrikSubGroup">
        <div data-role="group-repeat-intro">
            <?php echo $w->parseMessageForPlaceHolder($group->repeatIntro, $introData);?>
        </div>
    <?php
        // Add the add/remove repeat group buttons
        if ($group->editable && ($group->canAddRepeat || $group->canDeleteRepeat)) : ?>
            <div class="fabrikGroupRepeater pull-right btn-group">
                <?php if ($group->canAddRepeat) :
                    echo $this->addRepeatGroupButton;
                endif;
                if ($group->canDeleteRepeat) :
                    echo $this->removeRepeatGroupButton;
                endif;?>
            </div>
        <?php
        endif;
        ?>
        <div class="fabrikSubGroupElements">
            <?php

            // Load each group in a <ul>
            $this->elements = $subgroup;
            echo $this->loadTemplate('group');
            ?>
        </div><!-- end fabrikSubGroupElements -->
    </div><!-- end fabrikSubGroup -->
    <?php
    $i ++;

endforeach;

Georges
 
This will probably genefrate a lot of debug code, but there's no other way for me to see what's going on, so put ...

var_dump($subgroup)

... just after the foreach.

I'll need to see all the debug output.

-- hugh
 
Yes I tried, without much change so I did not pay much attention.
Now, re-trying, I think begin to understand something! Thank you, I will try to explain:

When I put

var_dump($subgroup)

just after the foreach, so my others groups (the others, not the one concerned), display a NULL. And the group concerned does not display nothing.

And if I try to use another field used in one of these other groups, yeah it works!
Indeed it displays the array and value, or it hides the group with your code. Good!

So the problem is only in a group, precisely in the one I need...
And it is exactly the only group which is in "Always show as read Only".

I think it is about my custom template, which has no effect on my group in readonly.

Georges
 
Last edited:
Hello

Just to update this post ...

Have you seen my last remark? I think it's a beginning of explanation.

Thanks!

Georges
 
Hmm, nope the subgroup data should still be there, even in read only. Tested it here.

I'm kind of at a loss here, the only way forward would be for me to do some hands on work on your server.

-- hugh
 
OK thank you but do not waste your time: as it is read-only in a subgroup, I finally went through an SQL view, and I do the exclusion directly in the SQL of the view.

thanks anyway!

Georges
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top