[BUGFIX] Prevent saving of invalid records 86/58386/4
authorFrank Naegler <frank.naegler@typo3.org>
Tue, 25 Sep 2018 10:00:26 +0000 (12:00 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 25 Sep 2018 14:49:43 +0000 (16:49 +0200)
This patch prevents saving an invalid record by click „close“
and „save“ in the modal.

Resolves: #86357
Releases: master
Change-Id: If7f581e9eaaf55dea463528563b7e679a6e65201
Reviewed-on: https://review.typo3.org/58386
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine.js

index ba26644..42d5193 100644 (file)
@@ -1148,7 +1148,7 @@ define(['jquery',
       var title = TYPO3.lang['label.confirm.close_without_save.title'] || 'Do you want to close without saving?';
       var content = TYPO3.lang['label.confirm.close_without_save.content'] || 'You currently have unsaved changes. Are you sure you want to discard these changes?';
       var $elem = $('<input />').attr('type', 'hidden').attr('name', '_saveandclosedok').attr('value', '1');
-      var $modal = Modal.confirm(title, content, Severity.warning, [
+      var buttons = [
         {
           text: TYPO3.lang['buttons.confirm.close_without_save.no'] || 'No, I will continue editing',
           btnClass: 'btn-default',
@@ -1158,14 +1158,18 @@ define(['jquery',
           text: TYPO3.lang['buttons.confirm.close_without_save.yes'] || 'Yes, discard my changes',
           btnClass: 'btn-default',
           name: 'yes'
-        },
-        {
+        }
+      ];
+      if ($('.has-error').length === 0) {
+        buttons.push({
           text: TYPO3.lang['buttons.confirm.save and close'] || 'Save and close',
           btnClass: 'btn-warning',
           name: 'save',
           active: true
-        }
-      ]);
+        });
+      }
+
+      var $modal = Modal.confirm(title, content, Severity.warning, buttons);
       $modal.on('button.clicked', function(e) {
         if (e.target.name === 'no') {
           Modal.dismiss();