Skip to content

Commit

Permalink
[imp] [33295] Adding the "showon" feature to JForm
Browse files Browse the repository at this point in the history
Close #3379
  • Loading branch information
chivitli authored and Bakual committed Mar 28, 2014
1 parent 9123898 commit 4e432ee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
20 changes: 14 additions & 6 deletions layouts/joomla/form/renderfield.php
Expand Up @@ -12,16 +12,24 @@
/**
* Layout variables
* ---------------------
* $hiddenLabel : (boolean) Do we have to show the label
* $label : (string) The html code for the label (not required if hiddenLabel is true)
* $input : (string) The input field html code
* $options : (array) Optional parameters
* $label : (string) The html code for the label (not required if $options['hiddenLabel'] is true)
* $input : (string) The input field html code
*/

?>

<div class="control-group">
<?php if (!isset($displayData['hiddenLabel']) || isset($displayData['hiddenLabel']) && $displayData['hiddenLabel'] == false) : ?>
<?php
if (!empty($displayData['options']['showonEnabled']))
{
JHtml::_('jquery.framework');
JHtml::_('script', 'jui/cms.js', false, true);
}
?>

<div class="control-group <?php echo $displayData['options']['class']; ?>" <?php echo $displayData['options']['rel']; ?>>
<?php if (empty($displayData['options']['hiddenLabel'])) : ?>
<div class="control-label"><?php echo $displayData['label']; ?></div>
<?php endif; ?>
<div class="controls"><?php echo $displayData['input']; ?></div>
</div>
</div>
23 changes: 21 additions & 2 deletions libraries/joomla/form/field.php
Expand Up @@ -900,8 +900,27 @@ public function renderField($options = array())
return $this->getInput();
}

$hiddenLabel = isset($options['hiddenLabel']) ? $options['hiddenLabel'] : false;
if (!isset($options['class']))
{
$options['class'] = '';
}

$options['rel'] = '';

if (empty($options['hiddenLabel']) && $this->getAttribute('hiddenLabel'))
{
$options['hiddenLabel'] = true;
}

if ($showon = $this->getAttribute('showon'))
{
$showon = explode(':', $showon, 2);
$options['class'] .= ' showon_' . implode(' showon_', explode(',', $showon[1]));
$id = $this->getName($showon[0]);
$options['rel'] = ' rel="showon_' . $id . '"';
$options['showonEnabled'] = true;
}

return JLayoutHelper::render($this->renderLayout, array('input' => $this->getInput(), 'label' => $this->getLabel(), 'hiddenLabel' => $hiddenLabel));
return JLayoutHelper::render($this->renderLayout, array('input' => $this->getInput(), 'label' => $this->getLabel(), 'options' => $options));
}
}

0 comments on commit 4e432ee

Please sign in to comment.