Skip to content

Commit

Permalink
Fields Subform: Improve the layout markup
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Sep 5, 2015
1 parent 59de7af commit 00310c4
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 24 deletions.
6 changes: 3 additions & 3 deletions layouts/joomla/form/field/subform/default.php
Expand Up @@ -28,10 +28,10 @@

<!-- Render fields for subform "<?php echo $fieldname; ?>" -->
<div class="subform-wrapper">
<label class="hasTooltip" title="<?php echo JHtml::tooltipText($label, $description); ?>" >
<legend class="hasTooltip" title="<?php echo JHtml::tooltipText($label, $description); ?>" >
<?php echo $label; ?>
</label>
<?php foreach($form->getGroup(false) as $field): ?>
</legend>
<?php foreach($form->getGroup('') as $field): ?>
<?php echo $field->renderField(); ?>
<?php endforeach; ?>
</div>
11 changes: 8 additions & 3 deletions layouts/joomla/form/field/subform/repeatable-table.php
Expand Up @@ -27,8 +27,11 @@
extract($displayData);

// Add script
JHtml::_('jquery.ui', array('core', 'sortable'));
JHtml::_('script', 'system/subform-repeatable.js', false, true);
if($multiple)
{
JHtml::_('jquery.ui', array('core', 'sortable'));
JHtml::_('script', 'system/subform-repeatable.js', false, true);
}

// Build heading
$table_head = '';
Expand All @@ -46,7 +49,7 @@
}
else
{
foreach($tmpl->getGroup(false) as $field) {
foreach($tmpl->getGroup('') as $field) {
$table_head .= '<th>' . strip_tags($field->label);
$table_head .= '<br /><small style="font-weight:normal">' . JText::_($field->description) . '</small>';
$table_head .= '</th>';
Expand All @@ -68,13 +71,15 @@
<thead>
<tr>
<?php echo $table_head; ?>
<?php if(!empty($buttons)):?>
<th style="width:8%;">
<?php if(!empty($buttons['add'])):?>
<div class="btn-group">
<a class="group-add btn btn-mini button btn-success"><span class="icon-plus"></span> </a>
</div>
<?php endif;?>
</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
Expand Down
Expand Up @@ -29,11 +29,13 @@
<?php endforeach; ?>
</td>
<?php endforeach; ?>
<?php if(!empty($buttons)):?>
<td>
<div class="btn-group">
<?php if(!empty($buttons['add'])):?><a class="group-add btn btn-mini button btn-success"><span class="icon-plus"></span> </a><?php endif;?>
<?php if(!empty($buttons['remove'])):?><a class="group-remove btn btn-mini button btn-danger"><span class="icon-minus"></span> </a><?php endif;?>
<?php if(!empty($buttons['move'])):?><a class="group-move btn btn-mini button btn-primary"><span class="icon-move"></span> </a><?php endif;?>
</div>
</td>
<?php endif; ?>
</tr>
Expand Up @@ -22,16 +22,18 @@
?>

<tr class="subform-repeatable-group" data-base-name="<?php echo $basegroup; ?>" data-group="<?php echo $group; ?>">
<?php foreach($form->getGroup(false) as $field): ?>
<?php foreach($form->getGroup('') as $field): ?>
<td>
<?php echo $field->renderField(); ?>
</td>
<?php endforeach; ?>
<?php if(!empty($buttons)):?>
<td>
<div class="btn-group">
<?php if(!empty($buttons['add'])):?><a class="group-add btn btn-mini button btn-success"><span class="icon-plus"></span> </a><?php endif;?>
<?php if(!empty($buttons['remove'])):?><a class="group-remove btn btn-mini button btn-danger"><span class="icon-minus"></span> </a><?php endif;?>
<?php if(!empty($buttons['move'])):?><a class="group-move btn btn-mini button btn-primary"><span class="icon-move"></span> </a><?php endif;?>
</div>
</td>
<?php endif; ?>
</tr>
13 changes: 8 additions & 5 deletions layouts/joomla/form/field/subform/repeatable.php
Expand Up @@ -27,8 +27,11 @@
extract($displayData);

// Add script
JHtml::_('jquery.ui', array('core', 'sortable'));
JHtml::_('script', 'system/subform-repeatable.js', false, true);
if($multiple)
{
JHtml::_('jquery.ui', array('core', 'sortable'));
JHtml::_('script', 'system/subform-repeatable.js', false, true);
}

$sublayout = empty($groupByFieldset) ? 'section' : 'section-byfieldsets';
?>
Expand All @@ -42,15 +45,15 @@
<div class="subform-repeatable"
data-bt-add="a.group-add" data-bt-remove="a.group-remove" data-bt-move="a.group-move"
data-repeatable-element="div.subform-repeatable-group" data-minimum="<?php echo $min; ?>" data-maximum="<?php echo $max; ?>">
<?php if(!empty($buttons['add'])):?>
<div class="btn-toolbar text-right">
<div class="btn-group">
<?php if(!empty($buttons['add'])):?>
<a class="group-add btn btn-mini button btn-success"><span class="icon-plus"></span> </a>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php
foreach($forms as $k => $form):
foreach($forms as $k => $form):
echo $this->sublayout($sublayout, array('form' => $form, 'basegroup' => $fieldname, 'group' => $fieldname . $k, 'buttons' => $buttons));
endforeach;
?>
Expand Down
Expand Up @@ -21,13 +21,15 @@
?>

<div class="subform-repeatable-group" data-base-name="<?php echo $basegroup; ?>" data-group="<?php echo $group; ?>">
<?php if(!empty($buttons)):?>
<div class="btn-toolbar text-right">
<div class="btn-group">
<?php if(!empty($buttons['add'])):?><a class="group-add btn btn-mini button btn-success"><span class="icon-plus"></span> </a><?php endif;?>
<?php if(!empty($buttons['remove'])):?><a class="group-remove btn btn-mini button btn-danger"><span class="icon-minus"></span> </a><?php endif;?>
<?php if(!empty($buttons['move'])):?><a class="group-move btn btn-mini button btn-primary"><span class="icon-move"></span> </a><?php endif;?>
</div>
</div>
<?php endif; ?>
<div class="row-fluid">
<?php foreach($form->getFieldsets() as $fieldset): ?>
<fieldset class="<?php if(!empty($fieldset->class)){ echo $fieldset->class; } ?>">
Expand Down
5 changes: 4 additions & 1 deletion layouts/joomla/form/field/subform/repeatable/section.php
Expand Up @@ -22,14 +22,17 @@
?>

<div class="subform-repeatable-group" data-base-name="<?php echo $basegroup; ?>" data-group="<?php echo $group; ?>">
<?php if(!empty($buttons)):?>
<div class="btn-toolbar text-right">
<div class="btn-group">
<?php if(!empty($buttons['add'])):?><a class="group-add btn btn-mini button btn-success"><span class="icon-plus"></span> </a><?php endif;?>
<?php if(!empty($buttons['remove'])):?><a class="group-remove btn btn-mini button btn-danger"><span class="icon-minus"></span> </a><?php endif;?>
<?php if(!empty($buttons['move'])):?><a class="group-move btn btn-mini button btn-primary"><span class="icon-move"></span> </a><?php endif;?>
</div>
</div>
<?php foreach($form->getGroup(false) as $field): ?>
<?php endif; ?>

<?php foreach($form->getGroup('') as $field): ?>
<?php echo $field->renderField(); ?>
<?php endforeach; ?>
</div>
19 changes: 8 additions & 11 deletions libraries/joomla/form/fields/subform.php
Expand Up @@ -14,10 +14,10 @@
/**
* Field to load a subform
*
* @Example:
* @Example with all attributes:
* <field name="field-name" type="subform"
* formsource="path/to/form.xml" max="3"
* layout="joomla.form.field.subform.repeatable-table" component="com_zcm" client="site"
* formsource="path/to/form.xml" min="1" max="3" multiple="true" buttons="add,remove,move"
* layout="joomla.form.field.subform.repeatable-table" groupByFieldset="false" component="com_example" client="site"
* label="Field Label" description="Field Description" />
*
*/
Expand Down Expand Up @@ -75,8 +75,10 @@ public function setup(SimpleXMLElement $element, $value, $group = null)
{
return false;
}

// Get the form source
$this->formsource = (string) $this->element['formsource'];

// Add root path if we have a path to XML file
if(strrpos($this->formsource, '.xml') === strlen($this->formsource) - 4)
{
Expand Down Expand Up @@ -111,11 +113,6 @@ public function setup(SimpleXMLElement $element, $value, $group = null)
protected function getInput()
{
$value = $this->value ? $this->value : array();
if($value && is_string($value))
{
// Guess there the json_encoded value
$value = json_decode($value, true);
}

// Prepare render data
$data = array();
Expand Down Expand Up @@ -156,7 +153,7 @@ protected function getInput()
return $e->getMessage();
}

// Show buttons
// Which buttons to show
$buttons_str = (string) $this->element['buttons'];
if($buttons_str)
{
Expand All @@ -166,7 +163,7 @@ protected function getInput()
}
else
{
$buttons = array('add' => true, 'remove' => true, 'move' => true);
$buttons = $this->multiple ? array('add' => true, 'remove' => true, 'move' => true) : array();
}

$data['tmpl'] = $tmpl;
Expand All @@ -189,7 +186,7 @@ protected function getInput()
// Render
$html = JLayoutHelper::render($this->layout, $data, null, array('client' => $client, 'component' => $component));

// Add hidden input on the front of subform inputs, in multiple mode
// Add hidden input on front of the subform inputs, in multiple mode
// for allow to submit the empty value
// @TODO: Remove when https://github.com/joomla/joomla-cms/pull/7381 will be fixed
if($this->multiple)
Expand Down

0 comments on commit 00310c4

Please sign in to comment.