Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<?php if (!empty($fieldSet->showon)) : ?>
<?php JHtml::_('jquery.framework'); ?>
<?php JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true)); ?>
<?php $dataShowOn = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($this->formControl, $fieldSet->showon)) . '\''; ?>
<?php $dataShowOn = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($this->form, $fieldSet)) . '\''; ?>
<?php endif; ?>
<?php $label = empty($fieldSet->label) ? 'COM_CONFIG_' . $name . '_FIELDSET_LABEL' : $fieldSet->label; ?>
<li<?php echo $dataShowOn; ?>><a data-toggle="tab" href="#<?php echo $name; ?>"><?php echo JText::_($label); ?></a></li>
Expand All @@ -80,7 +80,7 @@
<?php if ($field->showon) : ?>
<?php JHtml::_('jquery.framework'); ?>
<?php JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true)); ?>
<?php $dataShowOn = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($field->formControl, $field->showon)) . '\''; ?>
<?php $dataShowOn = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($this->form, $field)) . '\''; ?>
<?php endif; ?>
<?php if ($field->hidden) : ?>
<?php echo $field->input; ?>
Expand Down
2 changes: 1 addition & 1 deletion layouts/joomla/content/options_default.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{
JHtml::_('jquery.framework');
JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true));
$datashowon = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($field->formControl, $field->showon)) . '\'';
$datashowon = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($displayData->form, $field)) . '\'';
}
?>
<div class="control-group"<?php echo $datashowon; ?>>
Expand Down
2 changes: 1 addition & 1 deletion layouts/joomla/searchtools/default/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<?php if ($field->showon) : ?>
<?php JHtml::_('jquery.framework'); ?>
<?php JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true)); ?>
<?php $dataShowOn = " data-showon='" . json_encode(JFormHelper::parseShowOnConditions($field->formControl, $field->showon)) . "'"; ?>
<?php $dataShowOn = " data-showon='" . json_encode(JFormHelper::parseShowOnConditions($data['view']->filterForm, $field)) . "'"; ?>
<?php endif; ?>
<div class="js-stools-field-filter"<?php echo $dataShowOn; ?>>
<?php echo $field->input; ?>
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/form/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ public function renderField($options = array())

if ($this->showon)
{
$options['rel'] = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($this->formControl, $this->showon)) . '\'';
$options['rel'] = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($this->form, $this)) . '\'';
$options['showonEnabled'] = true;
}

Expand Down
33 changes: 26 additions & 7 deletions libraries/joomla/form/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,35 +320,54 @@ protected static function addPath($entity, $new = null)
/**
* Parse the show on conditions
*
* @param string $formControl Form name.
* @param string $showOn Show on conditions.
* @param JForm $form The form.
* @param JFormField $field The field with the showon condition.
*
* @return array Array with show on conditions.
*
* @since __DEPLOY_VERSION__
*/
public static function parseShowOnConditions($formControl, $showOn)
public static function parseShowOnConditions($form, $field)
{
// Process the showon data.
if (!$showOn)
if (!$form || !$field || !$field->showon)
{
return array();
}

$showOnData = array();
$showOnParts = preg_split('#\[AND\]|\[OR\]#', $showOn);
$showOnParts = preg_split('#(\[AND\]|\[OR\])#', $field->showon, -1, PREG_SPLIT_DELIM_CAPTURE);
$op = '';

foreach ($showOnParts as $showOnPart)
{
if ($showOnPart === '[AND]' || $showOnPart === '[OR]')
{
$op = trim($showOnPart, '[]');
continue;
}

$compareEqual = strpos($showOnPart, '!:') === false;
$showOnPartBlocks = explode(($compareEqual ? ':' : '!:'), $showOnPart, 2);

// Check if a group is being checked. will default to curren field group, if exists. Ex: params.show_title
$conditionFieldParts = explode('.', $showOnPartBlocks[0]);
$conditionFieldName = isset($conditionFieldParts[1]) ? $conditionFieldParts[1] : $conditionFieldParts[0];
$conditionFieldGroup = isset($conditionFieldParts[1]) ? $conditionFieldParts[0] : null;
$conditionFieldGroup = $conditionFieldGroup === null && property_exists($field, 'group') && $field->group ? $field->group : $conditionFieldGroup;
$conditionField = ($conditionField = $form->getField($conditionFieldName, $conditionFieldGroup)) ? $conditionField->name : $conditionFieldName;

$showOnData[] = array(
'field' => $formControl ? $formControl . '[' . $showOnPartBlocks[0] . ']' : $showOnPartBlocks[0],
'field' => str_replace('[]', '', $conditionField),
'values' => explode(',', $showOnPartBlocks[1]),
'sign' => $compareEqual === true ? '=' : '!=',
'op' => preg_match('#^\[(AND|OR)\]#', $showOnPart, $matches) ? $matches[1] : '',
'op' => $op,
);

if ($op !== '')
{
$op = '';
}
}

return $showOnData;
Expand Down