Dropdown Eval Populate ignores Disable setting

achartier

Super Moderator
Staff member
I am populating a dropdown using php in the Eval Populate field. I am creating an array[] using multiple JHTML::_('select.option', ...) statements. I wish to have one or more items in the dropdown list disabled (they are parents with children, only non-parents can be selected). I do this using the disable option of the JHTML::_ select option.

For example:
Code:
$opt = JHTML::_('select.option', $item->value, $item->name );
if ( $item->children > 0 )  $opt->disable = true;
$list[] = $opt;

When I return the $list the dropdown is rendered but the disable option is being ignored.
 
Alright, so here is a patch to fix the problem:

in components/com_fabrik/models/element.php insert the following function after the getSubOptionLabels function:

Code:
        /**
        * Get sub option enabled/disabled state
        *
        * @return  array
        */
 
        protected function getSubOptionEnDis()
        {
                $opts = array();
                $phpOpts = $this->getPhpOptions();
                if ($phpOpts)
                {
                        foreach ($phpOpts as $phpOpt)
                        {
                                $opts[] = $phpOpt->disable;
                        }
                }
                return $opts;
        }

And in plugins/fabrik_element/dropdown/dropdown.php

near line 58 find:
Code:
$labels = $this->getSubOptionLabels();

insert this after it:
Code:
$endis = $this->getSubOptionEnDis();

then change the foreach that follows as below:

Code:
foreach ($values as $tmpval)
{
            $tmpLabel = JArrayHelper::getValue($labels, $i);
            $disable = JArrayHelper::getValue($endis, $i);
            // For values like '1"'
            $tmpval = htmlspecialchars($tmpval, ENT_QUOTES);
            $opt = JHTML::_('select.option', $tmpval, $tmpLabel);
            $opt->disable = $disable;
            $opts[] = $opt;
            if (in_array($tmpval, $selected))
            {
                    $aRoValues[] = $this->getReadOnlyOutput($tmpval, $tmpLabel);
            }
            $i++;
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top