[BUGFIX] Check for form changes on exit 52/48752/3
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 30 Jun 2016 14:09:42 +0000 (16:09 +0200)
committerNicole Cordes <typo3@cordes.co>
Fri, 1 Jul 2016 08:45:15 +0000 (10:45 +0200)
Due to event juggling, setting the dirty state of a form does not work
for the first changed element. Because of this, the form is checked for
changes if a user clicks on the close button.

The original behavior was introdced with commit 003f9903 which is
reverted with this patch.

Resolves: #76893
Related: #45348
Releases: master
Change-Id: I45c2b05e096a2e7c18b8ce0aa584fc508f52ebdb
Reviewed-on: https://review.typo3.org/48752
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine.js

index d8152d9..6ef9fc0 100644 (file)
@@ -45,7 +45,6 @@ define(['jquery',
                ,openedPopupWindow: null
                ,legacyFieldChangedCb: function() { !$.isFunction(TYPO3.settings.FormEngine.legacyFieldChangedCb) || TYPO3.settings.FormEngine.legacyFieldChangedCb(); }
                ,browserUrl: ''
-               ,isDirty: false
        };
 
        /**
@@ -590,10 +589,7 @@ define(['jquery',
                FormEngine.initializeRemainingCharacterViews();
                FormEngine.initializeSelectCheckboxes();
 
-               $(document).on('change', 'input,textarea,select', function() {
-                       // Keep track of input fields to set the dirty state
-                       FormEngine.isDirty = $(document).find('.has-change').length > 0;
-               }).on('click', '.t3js-btn-moveoption-top, .t3js-btn-moveoption-up, .t3js-btn-moveoption-down, .t3js-btn-moveoption-bottom, .t3js-btn-removeoption', function(evt) {
+               $(document).on('click', '.t3js-btn-moveoption-top, .t3js-btn-moveoption-up, .t3js-btn-moveoption-down, .t3js-btn-moveoption-bottom, .t3js-btn-removeoption', function(evt) {
                        evt.preventDefault();
 
                        // track the arrows "Up", "Down", "Clear" etc in multi-select boxes
@@ -927,7 +923,7 @@ define(['jquery',
         * Show modal to confirm closing the document without saving
         */
        FormEngine.preventExitIfNotSaved = function() {
-               if (FormEngine.isDirty) {
+               if ($('form[name="' + FormEngine.formName + '"] .has-change').length > 0) {
                        var title = TYPO3.lang['label.confirm.close_without_save.title'] || 'Do you want to quit without saving?';
                        var content = TYPO3.lang['label.confirm.close_without_save.content'] || 'You have currently unsaved changes. Are you sure that you want to discard all changes?';
                        var $modal = Modal.confirm(title, content, Severity.warning, [