Skip to content

Commit 830cda6

Browse files
Thomas Hunzikerwilsonge
authored andcommitted
Fixing Showon in plugins/modules/templates (#13549)
* Adding field group to JFormHelper::parseShowOnConditions and rearranged argument order. * codestyle
1 parent ca6928e commit 830cda6

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

administrator/components/com_config/view/component/tmpl/default.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<?php if (!empty($fieldSet->showon)) : ?>
6161
<?php JHtml::_('jquery.framework'); ?>
6262
<?php JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true)); ?>
63-
<?php $dataShowOn = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($this->formControl, $fieldSet->showon)) . '\''; ?>
63+
<?php $dataShowOn = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($fieldSet->showon, $this->formControl)) . '\''; ?>
6464
<?php endif; ?>
6565
<?php $label = empty($fieldSet->label) ? 'COM_CONFIG_' . $name . '_FIELDSET_LABEL' : $fieldSet->label; ?>
6666
<li<?php echo $dataShowOn; ?>><a data-toggle="tab" href="#<?php echo $name; ?>"><?php echo JText::_($label); ?></a></li>
@@ -80,7 +80,7 @@
8080
<?php if ($field->showon) : ?>
8181
<?php JHtml::_('jquery.framework'); ?>
8282
<?php JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true)); ?>
83-
<?php $dataShowOn = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($field->formControl, $field->showon)) . '\''; ?>
83+
<?php $dataShowOn = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($field->showon, $field->formControl, $field->group)) . '\''; ?>
8484
<?php endif; ?>
8585
<?php if ($field->hidden) : ?>
8686
<?php echo $field->input; ?>

layouts/joomla/content/options_default.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{
3131
JHtml::_('jquery.framework');
3232
JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true));
33-
$datashowon = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($field->formControl, $field->showon)) . '\'';
33+
$datashowon = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($field->showon, $field->formControl, $field->group)) . '\'';
3434
}
3535
?>
3636
<div class="control-group"<?php echo $datashowon; ?>>

layouts/joomla/searchtools/default/filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<?php if ($field->showon) : ?>
2222
<?php JHtml::_('jquery.framework'); ?>
2323
<?php JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true)); ?>
24-
<?php $dataShowOn = " data-showon='" . json_encode(JFormHelper::parseShowOnConditions($field->formControl, $field->showon)) . "'"; ?>
24+
<?php $dataShowOn = " data-showon='" . json_encode(JFormHelper::parseShowOnConditions($field->showon, $field->formControl, $field->group)) . "'"; ?>
2525
<?php endif; ?>
2626
<div class="js-stools-field-filter"<?php echo $dataShowOn; ?>>
2727
<?php echo $field->input; ?>

libraries/joomla/form/field.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,8 @@ public function renderField($options = array())
952952

953953
if ($this->showon)
954954
{
955-
$options['rel'] = ' data-showon=\'' . json_encode(JFormHelper::parseShowOnConditions($this->formControl, $this->showon)) . '\'';
955+
$options['rel'] = ' data-showon=\'' .
956+
json_encode(JFormHelper::parseShowOnConditions($this->showon, $this->formControl, $this->group)) . '\'';
956957
$options['showonEnabled'] = true;
957958
}
958959

libraries/joomla/form/helper.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,15 @@ protected static function addPath($entity, $new = null)
320320
/**
321321
* Parse the show on conditions
322322
*
323-
* @param string $formControl Form name.
324323
* @param string $showOn Show on conditions.
324+
* @param string $formControl Form name.
325+
* @param string $group The dot-separated form group path.
325326
*
326327
* @return array Array with show on conditions.
327328
*
328329
* @since __DEPLOY_VERSION__
329330
*/
330-
public static function parseShowOnConditions($formControl, $showOn)
331+
public static function parseShowOnConditions($showOn, $formControl = null, $group = null)
331332
{
332333
// Process the showon data.
333334
if (!$showOn)
@@ -338,13 +339,20 @@ public static function parseShowOnConditions($formControl, $showOn)
338339
$showOnData = array();
339340
$showOnParts = preg_split('#\[AND\]|\[OR\]#', $showOn);
340341

342+
$formPath = $formControl ?: '';
343+
344+
if ($formPath && $group)
345+
{
346+
$formPath .= '[' . $group . ']';
347+
}
348+
341349
foreach ($showOnParts as $showOnPart)
342350
{
343351
$compareEqual = strpos($showOnPart, '!:') === false;
344352
$showOnPartBlocks = explode(($compareEqual ? ':' : '!:'), $showOnPart, 2);
345353

346354
$showOnData[] = array(
347-
'field' => $formControl ? $formControl . '[' . $showOnPartBlocks[0] . ']' : $showOnPartBlocks[0],
355+
'field' => $formPath ? $formPath . '[' . $showOnPartBlocks[0] . ']' : $showOnPartBlocks[0],
348356
'values' => explode(',', $showOnPartBlocks[1]),
349357
'sign' => $compareEqual === true ? '=' : '!=',
350358
'op' => preg_match('#^\[(AND|OR)\]#', $showOnPart, $matches) ? $matches[1] : '',

0 commit comments

Comments
 (0)