Commit 246aeeab authored by Carsten  Rose's avatar Carsten Rose
Browse files

#3502 / TemplateGroups: Checkboxen werden beim ersten Speichern (insert) nicht...

#3502 / TemplateGroups: Checkboxen werden beim ersten Speichern (insert) nicht geschrieben - ein anschliessendes Update ist ok
Das Problem tritt nur auf bei MultiCheckboxen. Neu werden im Store  STORE_ADDITIONAL_FORM_ELEMENTS (ist bereits frueher, extra fuer Checkboxen, eingefuehrt worden) fuer alle TemplateGroup FEs (type=checkbox) die Fake Elemente angelegt. Dazu wird neu NAME_TG_COPIES in dem FEs gefuellt mit dem 'TG max copies'-Wert.
parent 3b66411d
......@@ -1556,6 +1556,26 @@ abstract class AbstractBuildForm {
}
}
/**
* @param array $formElement
* @param $htmlFormElementName
* @param $htmlHidden
* @throws CodeException
* @throws UserFormException
*/
private function fillStoreAdditionalFormElementsCheckboxHidden(array $formElement, $htmlFormElementName, $htmlHidden) {
if (isset($formElement[NAME_TG_COPIES]) && $formElement[NAME_TG_COPIES] > 0) {
for ($ii = 1; $ii <= $formElement[NAME_TG_COPIES]; $ii++) {
$key = str_replace('%d', $ii, $htmlFormElementName);
$value = str_replace('%d', $ii, $htmlHidden);
$this->store->setVar($key, $value, STORE_ADDITIONAL_FORM_ELEMENTS, true);
}
} else {
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
}
}
/**
* Build as many Checkboxes as items.
*
......@@ -1582,7 +1602,7 @@ abstract class AbstractBuildForm {
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$htmlHidden = $this->buildNativeHidden($key, '');
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$this->fillStoreAdditionalFormElementsCheckboxHidden($formElement, $htmlFormElementName, $htmlHidden);
$html = '';
......@@ -1652,7 +1672,8 @@ abstract class AbstractBuildForm {
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$htmlHidden = $this->buildNativeHidden($key, '');
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$this->fillStoreAdditionalFormElementsCheckboxHidden($formElement, $htmlFormElementName, $htmlHidden);
$html = '';
......@@ -2898,6 +2919,21 @@ abstract class AbstractBuildForm {
return $html;
}
/**
* @param array $formElementArr
* @param $tgMaxCopies
* @return array
*/
private function fillFeSpecNativeCheckboxWithTgMax(array $formElementArr, $tgMaxCopies) {
foreach ($formElementArr as $key => $formElement) {
if ($formElement[FE_TYPE] = FE_TYPE_CHECKBOX) {
$formElementArr[$key][NAME_TG_COPIES] = $tgMaxCopies;
}
}
return $formElementArr;
}
/**
* Build a 'templateGroup'. Renders all assigned FormElements of the templateGroup.
* If there are already vlaues for the formElements, fill as much copies as values exist
......@@ -2955,15 +2991,18 @@ EOT;
// child FE's
$this->feSpecNative = $this->db->getNativeFormElements(SQL_FORM_ELEMENT_SPECIFIC_CONTAINER,
['yes', $this->formSpec["id"], 'native,container', $formElement['id']], $this->formSpec);
['yes', $this->formSpec[F_ID], 'native,container', $formElement[FE_ID]], $this->formSpec);
// Count defined FormElements in the current templateGroup
$elementsTotal = count($this->feSpecNative);
if ($elementsTotal < 1) {
// Nothting to do: return.
$this->feSpecNative = $feSpecNativeSave;
return '';
}
$this->feSpecNative = $this->fillFeSpecNativeCheckboxWithTgMax($this->feSpecNative, $max);
// If there are already elements filled, take them.
$html = $this->templateGroupCollectFilledElements($max, $htmlDelete, $json);
......
......@@ -626,6 +626,7 @@ const FE_WRAP_ROW_LABEL_INPUT_NOW = 'rowLabelInputNote';
const FE_MAX_LENGTH = 'maxLength';
const FE_PARAMETER = 'parameter';
const FE_TYPE_CHECKBOX = 'checkbox';
// FormElement columns: via parameter field
const FE_DATE_FORMAT = 'dateFormat'; // value: FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN
......@@ -818,4 +819,5 @@ const COLUMN_PAGEN = "pagen";
const COLUMN_PAGES = "pages";
const FORM_NAME_FORM = 'form';
const FORM_NAME_FORM_ELEMENT = 'formElement';
\ No newline at end of file
const FORM_NAME_FORM_ELEMENT = 'formElement';
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