I tried using the showon form field attribute in a front-end form with no working results.
Not even the example given here is working: https://docs.joomla.org/Form_field#Showon
Is there anything missing, do I have to include a certain script manually when I wanna use it in the front-end?
I'm using joomla 3.4.1, front end is a T3 template, in case that matters.
Any ideas or solutions ?
EDIT: The form
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset name="main">
<field name="foo" type="list" >
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="bar" type="text" showon="foo:1" />
<field name="foo2" type="text" />
<field name="bar2" type="text" showon="foo2:1" />
</fieldset>
</form>
The template
<?php
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
?>
<form action="...>"
method="post"
onsubmit="return false;"
name="adminForm" id="adminForm" class="form-validate">
<div class="form-horizontal adminform">
<fieldset class="">
<legend><?php echo 'test'; ?></legend>
<div class="span6">
<?php foreach ($this->form->getFieldset() as $field): ?>
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php endforeach; ?>
</div>
</fieldset>
</div>
<?php echo JHtml::_('form.token'); ?>
</form>
EDIT 2:Found a solution in joomla core files
if the template code above is updated from:
<div class="span6">
<?php foreach ($this->form->getFieldset() as $field): ?>
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php endforeach; ?>
</div>
To:
<div class="span6">
<?php foreach ($this->form->getFieldset() as $field): ?>
<?php
$class = '';
$rel = '';
if ($showon = $field->getAttribute('showon')) {
JHtml::_('jquery.framework');
JHtml::_('script', 'jui/cms.js', false, true);
$id = $this->form->getFormControl();
$showon = explode(':', $showon, 2);
$class = ' showon_' . implode(' showon_', explode(',', $showon[1]));
$rel = ' rel="showon_' . $id . '[' . $showon[0] . ']"';
}
?>
<div class="control-group<?php echo $class; ?>"<?php echo $rel; ?>>
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php endforeach; ?>
</div>
it works
SO am I supposed to manually add this part all the time?
Docu doesn't state anything about this, I need to load the cms.js file manually and build the control-grouptag myself? Seems strange