Commit 46ad1e67 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Refs 8091 - changes to render multi checkboxes with same name. Broken.

parent 76a15545
Pipeline #2777 passed with stages
in 2 minutes and 44 seconds
......@@ -2159,7 +2159,7 @@ abstract class AbstractBuildForm {
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h', true);
$htmlHidden = $this->buildNativeHidden($key, '');
$this->fillStoreAdditionalFormElementsCheckboxHidden($formElement, $htmlFormElementName, $htmlHidden);
......@@ -2173,13 +2173,13 @@ abstract class AbstractBuildForm {
for ($ii = 0, $jj = 1; $ii < count($itemKey); $ii++, $jj++) {
$jsonValue = false;
$classActive = '';
$htmlFormElementNameUniq = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, $ii);
$htmlFormElementNameUniq = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, $ii, true);
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID] . '-' . $ii);
$attribute .= Support::doAttribute('name', $htmlFormElementNameUniq);
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE] . '-' . $ii);
$attribute .= Support::doAttribute('value', $itemKey[$ii]);
$attribute .= Support::doAttribute('value', $itemKey[$ii], false);
// Check if the given key is found in field.
if (false !== array_search($itemKey[$ii], $values)) {
......@@ -2234,10 +2234,9 @@ abstract class AbstractBuildForm {
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$htmlHidden = $this->buildNativeHidden($key, '');
$this->fillStoreAdditionalFormElementsCheckboxHidden($formElement, $htmlFormElementName, $htmlHidden);
# $key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
# $htmlHidden = $this->buildNativeHidden($key, '');
# $this->fillStoreAdditionalFormElementsCheckboxHidden($formElement, $htmlFormElementName, $htmlHidden);
$html = '';
......@@ -2249,7 +2248,7 @@ abstract class AbstractBuildForm {
for ($ii = 0, $jj = 1; $ii < count($itemKey); $ii++, $jj++) {
$jsonValue = false;
$attribute = $attributeBase;
$htmlFormElementNameUniq = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, $ii);
$htmlFormElementNameUniq = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, $ii, true);
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID] . '-' . $ii);
$attribute .= Support::doAttribute('name', $htmlFormElementNameUniq);
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE] . '-' . $ii);
......@@ -2261,7 +2260,7 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('autofocus', $formElement[FE_AUTOFOCUS]);
}
$attribute .= Support::doAttribute('value', $itemKey[$ii]);
$attribute .= Support::doAttribute('value', $itemKey[$ii], false);
// Check if the given key is found in field.
if (false !== array_search($itemKey[$ii], $values)) {
......
......@@ -207,10 +207,17 @@ class HelperFormElement {
* @param string $field
* @param string $index
*
* @param bool $appendArray
* @return string
*/
public static function prependFormElementNameCheckBoxMulti($field, $index) {
return '_' . $index . '_' . $field;
public static function prependFormElementNameCheckBoxMulti($field, $index, $appendArray = false) {
// return '_' . $index . '_' . $field;
$key = '_' . $field;
if ($appendArray) {
$key .= '[]';
}
return $key;
}
/**
......
......@@ -12,7 +12,6 @@ use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Evaluate;
use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\Sanitize;
use IMATHUZH\Qfq\Core\Helper\Support;
......@@ -280,7 +279,7 @@ class FillStoreForm {
// FORM_REST: typically form elements are filled and created on form load. This does not exist for REST Forms.
// If a FE.value is defined, this has precedence over client supplied content.
if ($formMode == FORM_REST && $formElement[FE_VALUE]!='') {
if ($formMode == FORM_REST && $formElement[FE_VALUE] != '') {
$clientValues[$clientFieldName] = $this->evaluate->parse($formElement[FE_VALUE]);
}
......@@ -354,7 +353,19 @@ class FillStoreForm {
*/
private function collectMultiValues($clientFieldName, array $clientValues) {
$checkboxKey = HelperFormElement::prependFormElementNameCheckBoxMulti($clientFieldName, 'h');
$checkboxKey = HelperFormElement::prependFormElementNameCheckBoxMulti($clientFieldName, '', false);
if (!isset($clientValues[$checkboxKey])) {
return '';
}
// single: no array, multi: array
if (!is_array($clientValues[$checkboxKey])) {
return false;
}
return implode(',', $clientValues[$checkboxKey]);
// For templateGroups: all expanded FormElements will be tried to collect - this fails for not submitted fields.
// Therefore skip not existing clientvalues.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment