Commit c950445a authored by Carsten  Rose's avatar Carsten Rose
Browse files

Feature #3891 / Dynamic Update: Multiple Elements in a row - single show/hide

First implementation: Show / Hide via dynamicUpdate for a second element, wrapped in an own 'col-md' div.
parent 01764a20
......@@ -709,7 +709,7 @@ abstract class AbstractBuildForm {
*/
private function getFormElementForJson($htmlFormElementName, $value, array $formElement) {
$json = $this->getJsonFeMode($formElement[FE_MODE]);
$json = $this->getJsonFeMode($formElement[FE_MODE]); // disabled, required
$json['form-element'] = $htmlFormElementName;
$json['value'] = $value;
......@@ -724,17 +724,27 @@ abstract class AbstractBuildForm {
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $formElement[FE_NOTE];
}
// For FE.type='note': update the column 'input'
if (isset($formElement[FE_TYPE]) && $formElement[FE_TYPE] === FE_TYPE_NOTE) {
if (isset($formElement[FE_TYPE])) {
$key = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_INPUT;
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $value;
// For FE.type='note': update the column 'input'
if ($formElement[FE_TYPE] === FE_TYPE_NOTE) {
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $value;
}
// Check show/hide: only FE with FE_MODE_SQL given, might change.
if (!empty($formElement[FE_MODE_SQL])) {
$class = 'col-md-' . $formElement[FE_BS_INPUT_COLUMNS] . ' ';
$class .= ($formElement[FE_MODE] == FE_MODE_HIDDEN) ? 'hidden' : '';
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_ATTRIBUTE]['class'] = $class;
}
}
// Show/ Hide the complete FormElement Row.
// Show / Hide the complete FormElement Row.
if (isset($formElement[FE_HTML_ID])) { // HIDDEN_SIP comes without a real existing FE structure.
// Activate 'show' or 'hidden' on the current FormElement via JSON 'API_ELEMENT_UPDATE'
$class = $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_CLASS];
if ($formElement[FE_MODE] == 'hidden') {
if ($formElement[FE_MODE] == FE_MODE_HIDDEN) {
$class .= ' hidden';
}
......
......@@ -54,7 +54,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
// Element: Label + Input + Note
$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_CLASS] = "form-group clearfix";
//$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START] = "<div class='" . $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_CLASS] . "'>"; // Do not use. Use getRowOpenTag()
$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START] = "<div class='" . $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_CLASS] . "'>";
$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] = "</div>";
$this->wrap[WRAP_SETUP_SUBRECORD][WRAP_SETUP_START] = "<div class='col-md-12'>";
......@@ -80,6 +80,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
return "<div $class>";
}
/**
* @param $label
* @param $input
......@@ -520,11 +521,20 @@ EOF;
public function buildRowNative(array $formElement, $htmlElement, $htmlFormElementName) {
$html = '';
$htmlLabel = '';
$addClass = '';
$classHideRow = '';
$classHideElement = '';
$flagRowOpenTag = Support::findInSet('row', $formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE]);
$flagRowCloseTag = Support::findInSet('/row', $formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE]);
if ($formElement[FE_MODE] == FE_MODE_HIDDEN) {
if ($flagRowOpenTag && $flagRowCloseTag) {
$classHideRow = 'hidden';
} else {
$classHideElement = 'hidden';
}
}
// Label
if ($formElement[FE_BS_LABEL_COLUMNS] > 0) {
$htmlLabel = $this->buildLabel($htmlFormElementName, $formElement[FE_LABEL]);
......@@ -535,19 +545,16 @@ EOF;
// Input
$html .= $this->customWrap($formElement, $htmlElement, FE_WRAP_INPUT, $formElement[FE_BS_INPUT_COLUMNS],
[$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END]], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_INPUT);
[$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END]],
$formElement[FE_HTML_ID] . HTML_ID_EXTENSION_INPUT, $classHideElement);
// Note
$note = $formElement[FE_NOTE];
$html .= $this->customWrap($formElement, $note, FE_WRAP_NOTE, $formElement[FE_BS_NOTE_COLUMNS],
[$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END]], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_NOTE);
if ($formElement[FE_MODE] == FE_MODE_HIDDEN) {
$addClass = 'hidden';
}
// Row
$openTag = $flagRowOpenTag ? $this->getRowOpenTag($addClass) : '';
$openTag = $flagRowOpenTag ? $this->getRowOpenTag($classHideRow) : '';
$closeTag = $flagRowCloseTag ? $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] : '';
$html = $this->customWrap($formElement, $html, FE_WRAP_ROW, -1, [$openTag, $closeTag], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_ROW);
......@@ -568,10 +575,13 @@ EOF;
* @param string $wrapName FE_WRAP_ROW, FE_WRAP_LABEL, FE_WRAP_INPUT, FE_WRAP_NOTE
* @param int $bsColumns
* @param array $wrapArray Systemwide Defaults: [ 'open wrap', 'close wrap' ]
* @param string $htmlId
* @param string $class
* @return string Wrapped $htmlElement
* @throws CodeException
* @throws \qfq\UserFormException
*/
private function customWrap(array $formElement, $htmlElement, $wrapName, $bsColumns, array $wrapArray, $htmlId = '') {
private function customWrap(array $formElement, $htmlElement, $wrapName, $bsColumns, array $wrapArray, $htmlId = '', $class = '') {
// If $bsColumns==0: do not wrap with default.
if ($bsColumns == 0) {
......@@ -590,11 +600,13 @@ EOF;
if ($wrapArray[0] != '') {
$wrapArray[0] = Support::insertAttribute($wrapArray[0], 'id', $htmlId);
$wrapArray[0] = Support::insertAttribute($wrapArray[0], 'class', $class); // might be problematic, if there is already a 'class' defined.
}
return $wrapArray[0] . $htmlElement . $wrapArray[1];
}
/**
* @param $formElement
* @param $elementHtml
......
Markdown is supported
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