Commit 9a267b44 authored by Carsten  Rose's avatar Carsten Rose
Browse files

#3180=#2081 dynamicUpdate, rearrange 'input hidden' elements from checkboxes,...

#3180=#2081 dynamicUpdate, rearrange 'input hidden' elements from checkboxes, radios to top of form.

CODING.md: add some doc about STORE_ADDITIONAL_FORM_ELEMENTS.
load.php (#2081): rearrange delivered JSON to fullfill client API.
AbstractBuildForm.php: rename getJsonElementUpdate() to getFormElemenForJson(). Extend getFormElementForJson() to support changes for label and note. Fill store STORE_ADDITIONAL_FORM_ELEMENTS with 'hidden input' elments.
QuickFormQuery.php: implement Client JOSN API update.
parent 7c66b42d
...@@ -65,6 +65,13 @@ LOAD ...@@ -65,6 +65,13 @@ LOAD
AbstractBuildForm.php: process() > prepareT3VarsForSave() > Store.php: copyT3VarsToSip(); AbstractBuildForm.php: process() > prepareT3VarsForSave() > Store.php: copyT3VarsToSip();
* *Form save*: FillStoreForm.php: process() > Store: fillTypo3StoreFromSip() * *Form save*: FillStoreForm.php: process() > Store: fillTypo3StoreFromSip()
* Store: STORE_ADDITIONAL_FORM_ELEMENTS
* HTML 'hidden' elements, inside of a checkbox or radio input definition, might disturb Bootstrap CSS classes.
* Therefore HTML elements like 'hidden' can be collected in STORE_ADDITIONAL_FORM_ELEMENTS.
* When the form will be composed of all single parts, the STORE_ADDITIONAL_FORM_ELEMENTS content will be arranged before
the regular INPUT Elements.
* Formular zusammenbauen * Formular zusammenbauen
* QuickFormQuery: doForm > loadFormSpecification - laedt den Form Record alle Form Elemente die nicht genested sind: * QuickFormQuery: doForm > loadFormSpecification - laedt den Form Record alle Form Elemente die nicht genested sind:
native, pill, fieldset, templateGroup >> $his->formNative. native, pill, fieldset, templateGroup >> $his->formNative.
......
...@@ -65,6 +65,8 @@ try { ...@@ -65,6 +65,8 @@ try {
$answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS; $answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS;
$answer[API_MESSAGE] = 'load: success'; $answer[API_MESSAGE] = 'load: success';
$answer[API_FORM_UPDATE] = $data; $answer[API_FORM_UPDATE] = $data;
$answer[API_ELEMENT_UPDATE] = $data[API_ELEMENT_UPDATE];
unset($data[API_ELEMENT_UPDATE]);
} catch (qfq\UserFormException $e) { } catch (qfq\UserFormException $e) {
$answer[API_MESSAGE] = $e->formatMessage(); $answer[API_MESSAGE] = $e->formatMessage();
......
...@@ -23,7 +23,6 @@ require_once(__DIR__ . '/../qfq/helper/Support.php'); ...@@ -23,7 +23,6 @@ require_once(__DIR__ . '/../qfq/helper/Support.php');
require_once(__DIR__ . '/../qfq/helper/OnArray.php'); require_once(__DIR__ . '/../qfq/helper/OnArray.php');
require_once(__DIR__ . '/../qfq/report/Link.php'); require_once(__DIR__ . '/../qfq/report/Link.php');
/** /**
* Class AbstractBuildForm * Class AbstractBuildForm
* @package qfq * @package qfq
...@@ -186,10 +185,11 @@ abstract class AbstractBuildForm { ...@@ -186,10 +185,11 @@ abstract class AbstractBuildForm {
$htmlTail = $this->tail(); $htmlTail = $this->tail();
$htmlSubrecords = $this->doSubrecords(); $htmlSubrecords = $this->doSubrecords();
} }
$htmlHidden = $this->buildAdditionalFormElements();
$htmlSip = $this->buildHiddenSip($json); $htmlSip = $this->buildHiddenSip($json);
return ($mode === FORM_LOAD) ? $htmlHead . $htmlElements . $htmlSip . $htmlT3vars . $htmlTail . $htmlSubrecords : $json; return ($mode === FORM_LOAD) ? $htmlHead . $htmlHidden . $htmlElements . $htmlSip . $htmlT3vars . $htmlTail . $htmlSubrecords : $json;
} }
/** /**
...@@ -330,7 +330,7 @@ abstract class AbstractBuildForm { ...@@ -330,7 +330,7 @@ abstract class AbstractBuildForm {
abstract public function getProcessFilter(); abstract public function getProcessFilter();
/** /**
* Process all FormElements: build corresponding HTML code. Collect and return all HTML code & JSON. * Process all FormElements: Collect and return all HTML code & JSON.
* *
* @param $recordId * @param $recordId
* @param string $filter FORM_ELEMENTS_NATIVE | FORM_ELEMENTS_SUBRECORD | FORM_ELEMENTS_NATIVE_SUBRECORD * @param string $filter FORM_ELEMENTS_NATIVE | FORM_ELEMENTS_SUBRECORD | FORM_ELEMENTS_NATIVE_SUBRECORD
...@@ -351,7 +351,7 @@ abstract class AbstractBuildForm { ...@@ -351,7 +351,7 @@ abstract class AbstractBuildForm {
$html = ''; $html = '';
$flagOutput = false; $flagOutput = false;
// The following 'FormElement.parameter' will never be used during load (fe.type='upload'). // The following 'FormElement.parameter' will never be used during load (fe.type='upload'). FE_PARAMETER has been already expanded.
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER]; $skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER];
// get current data record // get current data record
...@@ -420,6 +420,7 @@ abstract class AbstractBuildForm { ...@@ -420,6 +420,7 @@ abstract class AbstractBuildForm {
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement[FE_TYPE]]; $buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement[FE_TYPE]];
$jsonElement = array(); $jsonElement = array();
$elementExtra = '';
// Render pure element // Render pure element
$elementHtml = $this->$buildElementFunctionName($formElement, $htmlFormElementName, $value, $jsonElement, $mode); $elementHtml = $this->$buildElementFunctionName($formElement, $htmlFormElementName, $value, $jsonElement, $mode);
...@@ -539,6 +540,20 @@ abstract class AbstractBuildForm { ...@@ -539,6 +540,20 @@ abstract class AbstractBuildForm {
abstract public function doSubrecords(); abstract public function doSubrecords();
/**
* Get all elements from STORE_ADDITIONAL_FORM_ELEMENTS and return them as a string.
*
* @return string
* @throws CodeException
* @throws \qfq\UserFormException
*/
private function buildAdditionalFormElements() {
$data = $this->store->getStore(STORE_ADDITIONAL_FORM_ELEMENTS);
return is_array($data) ? implode('', $data) : '';
}
/** /**
* Create a hidden sip, based on latest STORE_SIP Values. Return complete HTML 'hidden' element. * Create a hidden sip, based on latest STORE_SIP Values. Return complete HTML 'hidden' element.
* *
...@@ -560,26 +575,38 @@ abstract class AbstractBuildForm { ...@@ -560,26 +575,38 @@ abstract class AbstractBuildForm {
$sipValue = $sip->queryStringToSip($queryString, RETURN_SIP); $sipValue = $sip->queryStringToSip($queryString, RETURN_SIP);
$json[] = $this->getJsonElementUpdate(CLIENT_SIP, $sipValue, FE_MODE_SHOW); $json[] = $this->getFormElementForJson(CLIENT_SIP, $sipValue, [FE_MODE => FE_MODE_SHOW]);
return $this->buildNativeHidden(CLIENT_SIP, $sipValue); return $this->buildNativeHidden(CLIENT_SIP, $sipValue);
} }
/** /**
* Create an array with standard elements and add 'form-element', 'value'. * Create an array with standard elements for 'mode' (hidden, disabled, required) and add 'form-element', 'value'.
* 'Generic Element Update': add via API_ELEMENT_UPDATE 'label' and 'note'.
* All collected data as array - will be later converted to JSON.
* *
* @param $htmlFormElementName * @param string $htmlFormElementName
* @param string|array $value * @param string|array $value
* @param string $feMode disabled|readonly|'' * @param array $formElement
* @return array * @return array
*/ */
private function getJsonElementUpdate($htmlFormElementName, $value, $feMode) { private function getFormElementForJson($htmlFormElementName, $value, array $formElement) {
$json = $this->getJsonFeMode($feMode); $json = $this->getJsonFeMode($formElement[FE_MODE]);
$json['form-element'] = $htmlFormElementName; $json['form-element'] = $htmlFormElementName;
$json['value'] = $value; $json['value'] = $value;
if (isset($formElement[FE_LABEL])) {
$key = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_LABEL;
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $formElement[FE_LABEL];
}
if (isset($formElement[FE_NOTE])) {
$key = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_NOTE;
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $formElement[FE_NOTE];
}
return $json; return $json;
} }
...@@ -741,7 +768,7 @@ abstract class AbstractBuildForm { ...@@ -741,7 +768,7 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]); $attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return "$htmlTag $attribute>$textarea" . $this->getHelpBlock(); return "$htmlTag $attribute>$textarea" . $this->getHelpBlock();
...@@ -1234,7 +1261,9 @@ abstract class AbstractBuildForm { ...@@ -1234,7 +1261,9 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeList($formElement, ['autofocus']); $attribute .= $this->getAttributeList($formElement, ['autofocus']);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]); $attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$html = $this->buildNativeHidden($htmlFormElementName, $formElement['unchecked']); $htmlHidden = $this->buildNativeHidden($htmlFormElementName, $formElement['unchecked']);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
$htmlElement = '<input ' . $attribute . '>'; $htmlElement = '<input ' . $attribute . '>';
if (isset($formElement['label2'])) { if (isset($formElement['label2'])) {
...@@ -1247,7 +1276,7 @@ abstract class AbstractBuildForm { ...@@ -1247,7 +1276,7 @@ abstract class AbstractBuildForm {
$htmlElement, true); $htmlElement, true);
$html = Support::wrapTag('<div class="btn-group" data-toggle="buttons">', $html); $html = Support::wrapTag('<div class="btn-group" data-toggle="buttons">', $html);
$json = $this->getJsonElementUpdate($htmlFormElementName, $valueJson, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $valueJson, $formElement);
return $html; return $html;
} }
...@@ -1286,7 +1315,9 @@ abstract class AbstractBuildForm { ...@@ -1286,7 +1315,9 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeList($formElement, ['autofocus']); $attribute .= $this->getAttributeList($formElement, ['autofocus']);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]); $attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$html = $this->buildNativeHidden($htmlFormElementName, $formElement['unchecked']); $htmlHidden = $this->buildNativeHidden($htmlFormElementName, $formElement['unchecked']);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
$html .= '<input ' . $attribute . '>'; $html .= '<input ' . $attribute . '>';
if (isset($formElement['label2'])) { if (isset($formElement['label2'])) {
...@@ -1296,7 +1327,7 @@ abstract class AbstractBuildForm { ...@@ -1296,7 +1327,7 @@ abstract class AbstractBuildForm {
$html = Support::wrapTag("<label>", $html, true); $html = Support::wrapTag("<label>", $html, true);
$html = Support::wrapTag("<div class='checkbox'>", $html, true); $html = Support::wrapTag("<div class='checkbox'>", $html, true);
$json = $this->getJsonElementUpdate($htmlFormElementName, $valueJson, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $valueJson, $formElement);
return $html; return $html;
} }
...@@ -1351,7 +1382,11 @@ abstract class AbstractBuildForm { ...@@ -1351,7 +1382,11 @@ abstract class AbstractBuildForm {
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : ''); $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]); $attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$html = $this->buildNativeHidden(HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h'), ''); $key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$htmlHidden = $this->buildNativeHidden($key, '');
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
$attribute = $attributeBase; $attribute = $attributeBase;
if (isset($formElement['autofocus'])) { if (isset($formElement['autofocus'])) {
...@@ -1382,7 +1417,7 @@ abstract class AbstractBuildForm { ...@@ -1382,7 +1417,7 @@ abstract class AbstractBuildForm {
$html .= Support::wrapTag("<label class='btn " . $formElement[FE_BUTTON_CLASS] . "$classActive'>", $html .= Support::wrapTag("<label class='btn " . $formElement[FE_BUTTON_CLASS] . "$classActive'>",
$htmlElement, true); $htmlElement, true);
$json[] = $this->getJsonElementUpdate($htmlFormElementNameUniq, $jsonValue, $formElement[FE_MODE]); $json[] = $this->getFormElementForJson($htmlFormElementNameUniq, $jsonValue, $formElement);
// Init for the next checkbox // Init for the next checkbox
$attribute = $attributeBase; $attribute = $attributeBase;
...@@ -1417,7 +1452,11 @@ abstract class AbstractBuildForm { ...@@ -1417,7 +1452,11 @@ abstract class AbstractBuildForm {
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : ''); $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]); $attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$html = $this->buildNativeHidden(HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h'), ''); $key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$htmlHidden = $this->buildNativeHidden($key, '');
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
$orientation = ($formElement[FE_MAX_LENGTH] > 1) ? ALIGN_HORIZONTAL : ALIGN_VERTICAL; $orientation = ($formElement[FE_MAX_LENGTH] > 1) ? ALIGN_HORIZONTAL : ALIGN_VERTICAL;
$checkboxClass = ($orientation === ALIGN_HORIZONTAL) ? 'checkbox-inline' : 'checkbox'; $checkboxClass = ($orientation === ALIGN_HORIZONTAL) ? 'checkbox-inline' : 'checkbox';
...@@ -1470,7 +1509,7 @@ abstract class AbstractBuildForm { ...@@ -1470,7 +1509,7 @@ abstract class AbstractBuildForm {
} }
$html .= $htmlElement . $br; $html .= $htmlElement . $br;
$json[] = $this->getJsonElementUpdate($htmlFormElementNameUniq, $jsonValue, $formElement[FE_MODE]); $json[] = $this->getFormElementForJson($htmlFormElementNameUniq, $jsonValue, $formElement);
} }
...@@ -1582,8 +1621,10 @@ abstract class AbstractBuildForm { ...@@ -1582,8 +1621,10 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('autofocus', $formElement['autofocus']); $attribute .= Support::doAttribute('autofocus', $formElement['autofocus']);
} }
$html = $this->buildNativeHidden($htmlFormElementName, $value); $htmlHidden = $this->buildNativeHidden($htmlFormElementName, $value);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
for ($ii = 0; $ii < count($itemValue); $ii++) { for ($ii = 0; $ii < count($itemValue); $ii++) {
$classActive = ''; $classActive = '';
...@@ -1607,7 +1648,7 @@ abstract class AbstractBuildForm { ...@@ -1607,7 +1648,7 @@ abstract class AbstractBuildForm {
$html = Support::wrapTag('<div class="btn-group" data-toggle="buttons">', $html); $html = Support::wrapTag('<div class="btn-group" data-toggle="buttons">', $html);
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return $html; return $html;
} }
...@@ -1660,6 +1701,7 @@ abstract class AbstractBuildForm { ...@@ -1660,6 +1701,7 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('autofocus', $formElement['autofocus']); $attribute .= Support::doAttribute('autofocus', $formElement['autofocus']);
} }
$html = $this->buildNativeHidden($htmlFormElementName, $value); $html = $this->buildNativeHidden($htmlFormElementName, $value);
for ($ii = 0; $ii < count($itemValue); $ii++) { for ($ii = 0; $ii < count($itemValue); $ii++) {
...@@ -1699,7 +1741,7 @@ abstract class AbstractBuildForm { ...@@ -1699,7 +1741,7 @@ abstract class AbstractBuildForm {
$attribute = $attributeBase; $attribute = $attributeBase;
} }
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return $html; return $html;
} }
...@@ -1760,7 +1802,7 @@ abstract class AbstractBuildForm { ...@@ -1760,7 +1802,7 @@ abstract class AbstractBuildForm {
$option .= '>' . $itemValue[$ii] . '</option>'; $option .= '>' . $itemValue[$ii] . '</option>';
} }
$json = $this->getJsonElementUpdate($htmlFormElementName, $jsonValues, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $jsonValues, $formElement);
return '<select ' . $attribute . '>' . $option . '</select>' . $this->getHelpBlock(); return '<select ' . $attribute . '>' . $option . '</select>' . $this->getHelpBlock();
} }
...@@ -2226,7 +2268,7 @@ abstract class AbstractBuildForm { ...@@ -2226,7 +2268,7 @@ abstract class AbstractBuildForm {
// <button type="button" class="file-delete" data-sip="571d1fc9e6974"><span class="glyphicon glyphicon-trash"></span></button> // <button type="button" class="file-delete" data-sip="571d1fc9e6974"><span class="glyphicon glyphicon-trash"></span></button>
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return $htmlTextDelete . $htmlInputFile . $hiddenSipUpload; return $htmlTextDelete . $htmlInputFile . $hiddenSipUpload;
} }
...@@ -2329,7 +2371,7 @@ abstract class AbstractBuildForm { ...@@ -2329,7 +2371,7 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]); $attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return "<input $attribute>" . $this->getHelpBlock(); return "<input $attribute>" . $this->getHelpBlock();
...@@ -2461,7 +2503,7 @@ abstract class AbstractBuildForm { ...@@ -2461,7 +2503,7 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]); $attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]); $attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
$element = Support::wrapTag("<textarea $attribute>", htmlentities($value), false); $element = Support::wrapTag("<textarea $attribute>", htmlentities($value), false);
...@@ -2642,7 +2684,7 @@ abstract class AbstractBuildForm { ...@@ -2642,7 +2684,7 @@ abstract class AbstractBuildForm {
// restore parent processed FE's // restore parent processed FE's
$this->feSpecNative = $tmpStore; $this->feSpecNative = $tmpStore;
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]); $json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return $html; return $html;
} }
......
...@@ -321,8 +321,8 @@ class BuildFormBootstrap extends AbstractBuildForm { ...@@ -321,8 +321,8 @@ class BuildFormBootstrap extends AbstractBuildForm {
* @return string * @return string
*/ */
public function tail() { public function tail() {
$html = ''; $html = '';
// $html .= $this->buildNewSip();
$deleteUrl = ''; $deleteUrl = '';
$formId = $this->getFormId(); $formId = $this->getFormId();
......
...@@ -238,8 +238,10 @@ const STORE_ZERO = "0"; // value: 0, might helpfull if variable is empty but use ...@@ -238,8 +238,10 @@ const STORE_ZERO = "0"; // value: 0, might helpfull if variable is empty but use
const STORE_EMPTY = "E"; // value: '', might helpfull if variable is not defined and should result in an empty string instead of {{...}} (cause not replaced) const STORE_EMPTY = "E"; // value: '', might helpfull if variable is not defined and should result in an empty string instead of {{...}} (cause not replaced)
const STORE_SYSTEM = "Y"; // various system values like db connection credentials const STORE_SYSTEM = "Y"; // various system values like db connection credentials
const STORE_EXTRA = 'X'; // Persistent Store: contains arrays! Not Usefull for user. Used by system. const STORE_EXTRA = 'X'; // Persistent Store: contains arrays! Not Usefull for user. Used by system.
const STORE_ADDITIONAL_FORM_ELEMENTS = 'A'; // Internal Store to collect FormElements. Typically for 'hidden' elements of radio and checkbox. Helps render those elements at the end of the whole form rendering.
const STORE_USE_DEFAULT = "FSRVD"; const STORE_USE_DEFAULT = "FSRVD";
// //
// Store: Definitions / Members // Store: Definitions / Members
// //
...@@ -419,6 +421,8 @@ const API_FIELD_NAME = 'field-name'; ...@@ -419,6 +421,8 @@ const API_FIELD_NAME = 'field-name';
const API_FIELD_MESSAGE = 'field-message'; const API_FIELD_MESSAGE = 'field-message';
const API_FORM_UPDATE = 'form-update'; const API_FORM_UPDATE = 'form-update';
const API_ELEMENT_UPDATE = 'element-update'; const API_ELEMENT_UPDATE = 'element-update';
const API_ELEMENT_ATTRIBUTE = 'attr';
const API_ELEMENT_CONTENT = 'content';
const API_JSON_HIDDEN = 'hidden'; const API_JSON_HIDDEN = 'hidden';
const API_JSON_DISABLED = 'disabled'; const API_JSON_DISABLED = 'disabled';
......
...@@ -117,7 +117,6 @@ class QuickFormQuery { ...@@ -117,7 +117,6 @@ class QuickFormQuery {
* @param bool $phpUnit * @param bool $phpUnit
* @throws CodeException * @throws CodeException
* @throws UserFormException * @throws UserFormException
* @internal param string $bodytext
*/ */
public function __construct(array $t3data = array(), $phpUnit = false) { public function __construct(array $t3data = array(), $phpUnit = false) {
...@@ -344,6 +343,9 @@ class QuickFormQuery { ...@@ -344,6 +343,9 @@ class QuickFormQuery {
throw new CodeException("This statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN); throw new CodeException("This statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN);
} }
if (is_array($data)) {
$data = $this->groupElementUpdateEntries($data);
}
return $data; return $data;
} }
...@@ -697,6 +699,30 @@ class QuickFormQuery { ...@@ -697,6 +699,30 @@ class QuickFormQuery {
} }
/**
* Searches the whole array $dataArray on the second level for API_ELEMENT_UPDATE.
* All found elements collect under $collect[API_ELEMENT_UPDATE]... . Leave the rest unchanged.
*
* @param array $dataArray
* @return array to build JSON
*/
private function groupElementUpdateEntries(array $dataArray) {
$collect = array();
foreach ($dataArray as $data) {
if (isset($data[API_ELEMENT_UPDATE])) {
foreach ($data[API_ELEMENT_UPDATE] as $key => $item) {
$collect[API_ELEMENT_UPDATE][$key] = $item;
}
unset($data[API_ELEMENT_UPDATE]);
}
$collect[] = $data;
}
return $collect;
}
/** /**
* Process the SQL Queries from bodytext. Return the output. * Process the SQL Queries from bodytext. Return the output.
* *
......
...@@ -163,7 +163,8 @@ class Store { ...@@ -163,7 +163,8 @@ class Store {
STORE_ZERO => false, STORE_ZERO => false,
STORE_EMPTY => false, STORE_EMPTY => false,
STORE_SYSTEM => false, STORE_SYSTEM => false,
STORE_EXTRA => false STORE_EXTRA => false,
STORE_ADDITIONAL_FORM_ELEMENTS => false
]; ];
self::fillSystemStore($fileConfigIni); self::fillSystemStore($fileConfigIni);
......
...@@ -80,34 +80,36 @@ class BuildFormPlainTest extends AbstractDatabaseTest { ...@@ -80,34 +80,36 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$build = new \qfq\BuildFormPlain($form, array(), [$formElement]); $build = new \qfq\BuildFormPlain($form, array(), [$formElement]);
$label['123-l'][API_ELEMENT_CONTENT] = 'Name';
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" maxlength="255" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result); $this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" maxlength="255" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => ''], $json); $this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// CheckType // CheckType
$formElement['checkType'] = SANITIZE_ALLOW_MIN_MAX; $formElement['checkType'] = SANITIZE_ALLOW_MIN_MAX;
$formElement['checkPattern'] = '1|10'; $formElement['checkPattern'] = '1|10';
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" maxlength="255" value="" min="1" max="10" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result); $this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" maxlength="255" value="" min="1" max="10" data-hidden="no" data-disab