Commit 98fefcce authored by Carsten  Rose's avatar Carsten Rose
Browse files

AbstractBuildForm.php: fixed 'checkbox' update (api/load.php) - raw values...

AbstractBuildForm.php: fixed 'checkbox' update (api/load.php) - raw values like 'yes', 'no', 'enabled', 'disabled' are not understandable by the client (delivered via JSON) and needs to be converted to true/false.
parent 26d66e71
......@@ -319,12 +319,16 @@ abstract class AbstractBuildForm {
* @param $recordId
* @param string $filter FORM_ELEMENTS_NATIVE | FORM_ELEMENTS_SUBRECORD | FORM_ELEMENTS_NATIVE_SUBRECORD
* @param int $feIdContainer
* @param array $json
* @param string $modeCollectFe
* @param bool $htmlElementNameIdZero
* @param string $storeUse
* @return string
* @throws CodeException
* @throws DbException
* @throws \qfq\UserFormException
*/
public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE, $feIdContainer = 0, &$json,
public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE, $feIdContainer = 0, array &$json,
$modeCollectFe = FLAG_DYNAMIC_UPDATE, $htmlElementNameIdZero = false, $storeUse = STORE_USE_DEFAULT) {
$html = '';
......@@ -417,12 +421,12 @@ abstract class AbstractBuildForm {
/**
* Create a hidden sip, based on latest STORE_SIP Values. Return complete HTML 'hidden' element.
*
* @param $json
* @param array $json
* @return string <input type='hidden' name='s' value='<sip>'>
* @throws CodeException
* @throws \qfq\UserFormException
*/
public function buildHiddenSip(&$json) {
public function buildHiddenSip(array &$json) {
$sipArray = $this->store->getStore(STORE_SIP);
unset($sipArray[SIP_SIP]);
unset($sipArray[SIP_URLPARAM]);
......@@ -444,12 +448,11 @@ abstract class AbstractBuildForm {
* @return array
*/
private function getJsonElementUpdate($htmlFormElementId, $value, $feMode) {
$json = $this->getJsonFeMode($feMode);
$json['form-element'] = $htmlFormElementId;
$json['value'] = $value;
// $json['disabled'] = ($feMode === 'disabled');
// $json['readonly'] = ($feMode === 'readonly');
return $json;
}
......@@ -570,10 +573,11 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return string
* @throws UserFormException
* @throws \qfq\UserFormException
*/
public function buildInput(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildInput(array $formElement, $htmlFormElementId, $value, array &$json) {
$textarea = '';
$attribute = Support::doAttribute('name', $htmlFormElementId);
......@@ -812,10 +816,12 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return string
* @throws UserFormException
* @throws CodeException
* @throws \qfq\UserFormException
*/
public function buildCheckbox(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildCheckbox(array $formElement, $htmlFormElementId, $value, array &$json) {
$itemKey = array();
$itemValue = array();
......@@ -840,17 +846,15 @@ abstract class AbstractBuildForm {
switch ($formElement['checkBoxMode']) {
case 'single':
$html = $this->buildCheckboxSingle($formElement, $htmlFormElementId, $attributeBase, $value);
$html = $this->buildCheckboxSingle($formElement, $htmlFormElementId, $attributeBase, $value, $json);
break;
case 'multi';
$html = $this->buildCheckboxMulti($formElement, $htmlFormElementId, $attributeBase, $value, $itemKey, $itemValue);
$html = $this->buildCheckboxMulti($formElement, $htmlFormElementId, $attributeBase, $value, $itemKey, $itemValue, $json);
break;
default:
throw new UserFormException('checkBoxMode: \'' . $formElement['checkBoxMode'] . '\' is unknown.', ERROR_CHECKBOXMODE_UNKNOWN);
}
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
// return Support::wrapTag('<div class="checkbox">', $html, true);
return $html;
}
......@@ -1016,10 +1020,12 @@ abstract class AbstractBuildForm {
* @param $htmlFormElementId
* @param $attribute
* @param $value
* @param array $json
* @return string
*/
public function buildCheckboxSingle(array $formElement, $htmlFormElementId, $attribute, $value) {
public function buildCheckboxSingle(array $formElement, $htmlFormElementId, $attribute, $value, array &$json) {
$html = '';
$valueJson = false;
$attribute .= Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('value', $formElement['checked'], false);
......@@ -1028,6 +1034,7 @@ abstract class AbstractBuildForm {
if ($formElement['checked'] === $value) {
$attribute .= Support::doAttribute('checked', 'checked');
$valueJson = true;
}
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
......@@ -1042,6 +1049,8 @@ abstract class AbstractBuildForm {
$html = Support::wrapTag("<label>", $html, true);
$html = Support::wrapTag("<div class='checkbox'>", $html, true);
$json = $this->getJsonElementUpdate($htmlFormElementId, $valueJson, $formElement[FE_MODE]);
return $html;
}
......@@ -1057,9 +1066,10 @@ abstract class AbstractBuildForm {
* @param $value
* @param array $itemKey
* @param array $itemValue
* @param array $json
* @return string
*/
public function buildCheckboxMulti(array $formElement, $htmlFormElementId, $attributeBase, $value, array $itemKey, array $itemValue) {
public function buildCheckboxMulti(array $formElement, $htmlFormElementId, $attributeBase, $value, array $itemKey, array $itemValue, array &$json) {
// Defines which of the checkboxes will be checked.
$values = explode(',', $value);
......@@ -1075,7 +1085,7 @@ abstract class AbstractBuildForm {
$flagFirst = true;
for ($ii = 0, $jj = 1; $ii < count($itemKey); $ii++, $jj++) {
$jsonValue = false;
$attribute = $attributeBase;
// Do this only the first round.
......@@ -1090,6 +1100,7 @@ abstract class AbstractBuildForm {
// Check if the given key is found in field.
if (false !== array_search($itemKey[$ii], $values)) {
$attribute .= Support::doAttribute('checked', 'checked');
$jsonValue = true;
}
// '&nbsp;' - This is necessary to correctly align an empty input.
......@@ -1118,6 +1129,8 @@ abstract class AbstractBuildForm {
}
$html .= $htmlElement . $br;
$json[] = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
}
// if (isset($formElement[CHECKBOX_ORIENTATION]) && $formElement[CHECKBOX_ORIENTATION] !== 'vertical')
......@@ -1135,9 +1148,12 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return string
* @throws CodeException
* @throws \qfq\UserFormException
*/
public function buildHidden(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildHidden(array $formElement, $htmlFormElementId, $value, array &$json) {
$this->store->setVar($htmlFormElementId, $value, STORE_SIP, false);
}
......@@ -1154,10 +1170,12 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return string
* @throws UserFormException
* @throws CodeException
* @throws \qfq\UserFormException
*/
public function buildRadio(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildRadio(array $formElement, $htmlFormElementId, $value, array &$json) {
$itemKey = array();
$itemValue = array();
......@@ -1229,9 +1247,12 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return mixed
* @throws CodeException
* @throws \qfq\UserFormException
*/
public function buildSelect(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildSelect(array $formElement, $htmlFormElementId, $value, array &$json) {
$itemKey = array();
$itemValue = array();
......@@ -1284,10 +1305,12 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return string
* @throws UserFormException
* @throws CodeException
* @throws \qfq\UserFormException
*/
public function buildSubrecord(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildSubrecord(array $formElement, $htmlFormElementId, $value, array &$json) {
$rcText = false;
$nameColumnId = 'id';
$targetTableName = '';
......@@ -1626,10 +1649,12 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return string
* @throws UserFormException
* @throws CodeException
* @throws \qfq\UserFormException
*/
public function buildFile(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildFile(array $formElement, $htmlFormElementId, $value, array &$json) {
$attribute = '';
$arr = array();
......@@ -1686,10 +1711,11 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return string
* @throws UserFormException
* @throws \qfq\UserFormException
*/
public function builddateJQW(array $formElement, $htmlFormElementId, $value, &$json) {
public function builddateJQW(array $formElement, $htmlFormElementId, $value, array &$json) {
$textarea = '';
$attribute = Support::doAttribute('name', $htmlFormElementId);
......@@ -1739,11 +1765,11 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param $json
* @param array $json
* @return string
* @throws UserFormException
*/
public function buildDateTime(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildDateTime(array $formElement, $htmlFormElementId, $value, array &$json) {
$attribute = Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('class', 'form-control');
......@@ -1848,9 +1874,10 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return mixed
*/
public function buildNote(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildNote(array $formElement, $htmlFormElementId, $value, array &$json) {
return $value;
}
......@@ -1860,9 +1887,10 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return mixed
*/
public function buildPill(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildPill(array $formElement, $htmlFormElementId, $value, array &$json) {
return $value;
}
......@@ -1872,9 +1900,12 @@ abstract class AbstractBuildForm {
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @param array $json
* @return mixed
* @throws CodeException
* @throws DbException
*/
public function buildFieldset(array $formElement, $htmlFormElementId, $value, &$json) {
public function buildFieldset(array $formElement, $htmlFormElementId, $value, array &$json) {
$attribute = '';
// save parent processed FE's
......
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