Commit c529deac authored by Harald Atteneder's avatar Harald Atteneder Committed by Tobi Kretschmann
Browse files

[TASK] Keep old value on confirmation modal close

When changing the doktype a confirmation modal appears. This patch
reverts the value of the field to the original value after closing the
modal without clicking *OK*.

This works for all selects with 'onChange' => 'reload' and
'renderType' => 'selectSingle'

Resolves: #89220
Releases: master,9.5
Change-Id: I6d479f9180d64e8e4c25e96f52e60dca36863fd9
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61809


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarSascha Rademacher <sascha.rademacher+typo3@gmail.com>
Tested-by: default avatarTobi Kretschmann <tobi@tobishome.de>
Reviewed-by: default avatarSascha Rademacher <sascha.rademacher+typo3@gmail.com>
Reviewed-by: default avatarTobi Kretschmann <tobi@tobishome.de>
parent 015520cd
......@@ -196,6 +196,7 @@ class SelectSingleElement extends AbstractFormElement
'name' => $parameterArray['itemFormElName'],
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'class' => 'form-control form-control-adapt',
'data-original-value' => $selectedValue,
];
if ($size) {
$selectAttributes['size'] = $size;
......
......@@ -1225,8 +1225,13 @@ define(['jquery',
FormEngine.requestConfirmationOnFieldChange = function(fieldName, showConfirmation) {
const $field = FormEngine.getFieldElement(fieldName);
$field.on('change', function() {
const originalValue = $field.data('original-value');
let documentUpdated = false;
if (showConfirmation) {
if ($field.val() != originalValue) {
const $modal = Modal.confirm(
TYPO3.lang['FormEngine.refreshRequiredTitle'],
TYPO3.lang['FormEngine.refreshRequiredContent']
......@@ -1235,10 +1240,19 @@ define(['jquery',
$modal.on('button.clicked', function(e) {
if (e.target.name === 'ok') {
FormEngine.saveDocument();
documentUpdated = true
}
Modal.dismiss();
});
$modal.on('hide.bs.modal', function(e) {
// Revert to previous value if document is not saved.
// Trigger js event to update icon in custom select input.
if (!documentUpdated && originalValue) {
$field.val(originalValue);
$field.trigger('change');
}
});
}
} else {
FormEngine.saveDocument();
}
......
......@@ -536,7 +536,12 @@ define(['jquery', 'moment'], function($, moment) {
*/
FormEngineValidation.markFieldAsChanged = function($field) {
var $paletteField = $field.closest('.t3js-formengine-palette-field');
if ($field.data('original-value') && $field.data('original-value') == $field.val()) {
$paletteField.removeClass('has-change');
} else {
$paletteField.addClass('has-change');
}
};
/**
......
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