Skip to content

Commit

Permalink
Adapt checkboxes and radio
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Dec 4, 2016
1 parent e9efe57 commit 91e2d9f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 39 deletions.
18 changes: 9 additions & 9 deletions components/com_fields/layouts/field/prepare/checkboxes.php
Expand Up @@ -13,23 +13,23 @@
return;
}

$field = $displayData['field'];
$value = $field->value;
$field = $displayData['field'];
$fieldValue = $field->value;

if (!$value)
if (!$fieldValue)
{
return;
}

$value = (array) $value;
$texts = array();
$options = JFormAbstractlist::getOptionsFromField($field);
$fieldValue = (array) $fieldValue;
$texts = array();
$options = JFormAbstractlist::getOptionsFromField($field);

foreach ($options as $optionValue => $optionText)
foreach ($options as $value => $name)
{
if (in_array($optionValue, $value))
if (in_array($value, $fieldValue))
{
$texts[] = JText::_($optionText);
$texts[] = JText::_($name);
}
}

Expand Down
18 changes: 9 additions & 9 deletions components/com_fields/layouts/field/prepare/list.php
Expand Up @@ -13,23 +13,23 @@
return;
}

$field = $displayData['field'];
$value = $field->value;
$field = $displayData['field'];
$fieldValue = $field->value;

if (!$value)
if (!$fieldValue)
{
return;
}

$value = (array) $value;
$texts = array();
$options = JFormAbstractlist::getOptionsFromField($field);
$fieldValue = (array) $fieldValue;
$texts = array();
$options = JFormAbstractlist::getOptionsFromField($field);

foreach ($options as $option)
foreach ($options as $value => $name)
{
if (in_array($option->value, $value))
if (in_array($value, $fieldValue))
{
$texts[] = JText::_($optionText);
$texts[] = JText::_($name);
}
}

Expand Down
11 changes: 7 additions & 4 deletions libraries/joomla/form/abstractlist.php
Expand Up @@ -219,7 +219,7 @@ public static function getOptionsFromField($field)

foreach ($options as $option)
{
$data[$option->name] = $options->value;
$data[$option->value] = $option->name;
}

return $data;
Expand All @@ -239,10 +239,13 @@ public static function getOptionsFromField($field)
*/
protected function postProcessDomNode($field, DOMElement $fieldNode, JForm $form)
{
foreach (self::getOptionsFromField($field) as $index => $name)
foreach (self::getOptionsFromField($field) as $value => $name)
{
$element = $fieldNode->appendChild(new DOMElement('option', $name));
$element->setAttribute('value', $index);
$option = new DOMElement('option', $value);
$option->nodeValue = JText::_($name);

$element = $fieldNode->appendChild($option);
$element->setAttribute('value', $value);
}

return parent::postProcessDomNode($field, $fieldNode, $form);
Expand Down
8 changes: 7 additions & 1 deletion libraries/joomla/form/field.php
Expand Up @@ -1113,7 +1113,13 @@ public function appendXMLFieldTag($field, DOMElement $parent, JForm $form)
{
if (is_array($param))
{
$param = implode(',', $param);
// Multidimensional arrays (eg. list options) can't be transformed properly
$param = count($param) == count($param, COUNT_RECURSIVE) ? implode(',', $param) : '';
}

if (!$param)
{
continue;
}

$node->setAttribute($key, $param);
Expand Down
16 changes: 8 additions & 8 deletions libraries/joomla/form/parameters/checkboxes.xml
Expand Up @@ -4,26 +4,26 @@
<fieldset name="fieldparams">
<field
name="options"
type="Repeatable"
icon="list"
description="JLIB_FORM_FIELD_PARAM_CHECKBOX_MULTIPLE_VALUES_DESC"
label="JLIB_FORM_FIELD_PARAM_CHECKBOX_MULTIPLE_VALUES_LABEL"
type="subform" layout="joomla.form.field.subform.repeatable-table"
icon="list" multiple="true"
description="JLIB_FORM_FIELD_PARAM_LIST_MULTIPLE_VALUES_DESC"
label="JLIB_FORM_FIELD_PARAM_LIST_MULTIPLE_VALUES_LABEL"
>
<fieldset hidden="true" name="list_templates_modal" repeat="true">
<form hidden="true" name="list_templates_modal" repeat="true">
<field
name="name"
label="JLIB_FORM_FIELD_PARAM_CHECKBOX_MULTIPLE_VALUES_NAME_LABEL"
label="JLIB_FORM_FIELD_PARAM_LIST_MULTIPLE_VALUES_NAME_LABEL"
size="30"
type="text"
/>

<field
name="value"
label="JLIB_FORM_FIELD_PARAM_CHECKBOX_MULTIPLE_VALUES_VALUE_LABEL"
label="JLIB_FORM_FIELD_PARAM_LIST_MULTIPLE_VALUES_VALUE_LABEL"
size="30"
type="text"
/>
</fieldset>
</form>
</field>
</fieldset>
</fields>
Expand Down
16 changes: 8 additions & 8 deletions libraries/joomla/form/parameters/radio.xml
Expand Up @@ -4,26 +4,26 @@
<fieldset name="fieldparams">
<field
name="options"
type="Repeatable"
icon="list"
description="JLIB_FORM_FIELD_PARAM_RADIO_MULTIPLE_VALUES_DESC"
label="JLIB_FORM_FIELD_PARAM_RADIO_MULTIPLE_VALUES_LABEL"
type="subform" layout="joomla.form.field.subform.repeatable-table"
icon="list" multiple="true"
description="JLIB_FORM_FIELD_PARAM_LIST_MULTIPLE_VALUES_DESC"
label="JLIB_FORM_FIELD_PARAM_LIST_MULTIPLE_VALUES_LABEL"
>
<fieldset hidden="true" name="list_templates_modal" repeat="true">
<form hidden="true" name="list_templates_modal" repeat="true">
<field
name="name"
label="JLIB_FORM_FIELD_PARAM_RADIO_MULTIPLE_VALUES_NAME_LABEL"
label="JLIB_FORM_FIELD_PARAM_LIST_MULTIPLE_VALUES_NAME_LABEL"
size="30"
type="text"
/>

<field
name="value"
label="JLIB_FORM_FIELD_PARAM_RADIO_MULTIPLE_VALUES_VALUE_LABEL"
label="JLIB_FORM_FIELD_PARAM_LIST_MULTIPLE_VALUES_VALUE_LABEL"
size="30"
type="text"
/>
</fieldset>
</form>
</field>
</fieldset>
</fields>
Expand Down

0 comments on commit 91e2d9f

Please sign in to comment.