Commit c2ba4543 authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Richard Haeser
Browse files

[BUGFIX] Fix change=reload for group fields

This patch implements the "Refresh required" dialog for group fields
configured to request a reload once their value changes.
In the same run the validation is now applied to the field holding the
actual value, which requires a minor change in the validation process.

Resolves: #93855
Releases: master
Change-Id: I1a1cd1ff65230da23c820b94b82644d860e06f39
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68671


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: default avatarRiny van Tiggelen <info@online-gamer.nl>
Tested-by: Richard Haeser's avatarRichard Haeser <richard@richardhaeser.com>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: default avatarRiny van Tiggelen <info@online-gamer.nl>
Reviewed-by: Richard Haeser's avatarRichard Haeser <richard@richardhaeser.com>
parent 12737d31
......@@ -246,7 +246,6 @@ class GroupElement extends AbstractFormElement
$selectorAttributes = [
'id' => $fieldId,
'data-formengine-input-name' => htmlspecialchars($elementName),
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'data-maxitems' => (string)$maxItems,
'size' => (string)$size,
];
......@@ -358,7 +357,12 @@ class GroupElement extends AbstractFormElement
$html[] = '</div>';
}
$html[] = '</div>';
$html[] = '<input type="hidden" name="' . htmlspecialchars($elementName) . '" value="' . htmlspecialchars(implode(',', $listOfSelectedValues)) . '" />';
$html[] = '<input type="hidden"';
$html[] = ' data-formengine-validation-rules="' . htmlspecialchars($this->getValidationDataAsJsonString($config)) . '"';
$html[] = ' name="' . htmlspecialchars($elementName) . '"';
$html[] = ' value="' . htmlspecialchars(implode(',', $listOfSelectedValues)) . '"';
$html[] = ' onchange="' . htmlspecialchars(implode('', $parameterArray['fieldChangeFunc'])) . '"';
$html[] = ' />';
$html[] = '</div>';
$resultArray['requireJsModules'][] = ['TYPO3/CMS/Backend/FormEngine/Element/GroupElement' => '
......
......@@ -96,13 +96,14 @@ define(['jquery',
exclusiveValues = String(exclusiveValues);
var $fieldEl,
$originalFieldEl,
originalFieldEl,
isMultiple = false,
isList = false;
$originalFieldEl = $fieldEl = FormEngine.getFieldElement(fieldName);
$fieldEl = FormEngine.getFieldElement(fieldName);
originalFieldEl = $fieldEl.get(0);
if ($originalFieldEl.length === 0 || value === '--div--') {
if (originalFieldEl === null || value === '--div--') {
return;
}
......@@ -182,11 +183,11 @@ define(['jquery',
$option.appendTo($fieldEl);
// set the hidden field
FormEngine.updateHiddenFieldValueFromSelect($fieldEl, $originalFieldEl);
FormEngine.updateHiddenFieldValueFromSelect($fieldEl, originalFieldEl);
// execute the phpcode from $FormEngine->TBE_EDITOR_fieldChanged_func
FormEngine.legacyFieldChangedCb();
FormEngineValidation.markFieldAsChanged($originalFieldEl);
FormEngineValidation.markFieldAsChanged(originalFieldEl);
FormEngine.Validation.validateField($fieldEl);
FormEngine.Validation.validateField($availableFieldEl);
}
......@@ -224,7 +225,8 @@ define(['jquery',
// make a comma separated list, if it is a multi-select
// set the values to the final hidden field
$(originalFieldEl).val(selectedValues.join(','));
originalFieldEl.value = selectedValues.join(',');
originalFieldEl.dispatchEvent(new Event('change', {bubbles: true, cancelable: true}));
};
/**
......@@ -700,16 +702,26 @@ define(['jquery',
$modal.on('button.clicked', function(e) {
if (e.target.name === 'ok') {
FormEngine.closeModalsRecursive();
FormEngine.saveDocument();
} else {
Modal.dismiss();
}
Modal.dismiss();
});
} else {
FormEngine.saveDocument();
}
};
FormEngine.closeModalsRecursive = function() {
if (typeof Modal.currentModal !== 'undefined' && Modal.currentModal !== null) {
Modal.currentModal.on('hidden.bs.modal', function () {
FormEngine.closeModalsRecursive(Modal.currentModal);
});
Modal.currentModal.trigger('modal-dismiss');
}
}
/**
* Preview action
*
......
......@@ -343,7 +343,7 @@ define([
break;
case 'group':
if (rule.minItems || rule.maxItems) {
selected = field.querySelectorAll('option').length;
selected = FormEngineValidation.trimExplode(',', field.value).length;
if (typeof rule.minItems !== 'undefined') {
minItems = rule.minItems * 1;
if (!isNaN(minItems) && selected < minItems) {
......
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