Skip to content

Commit

Permalink
FIX ModelAdmin toast elements
Browse files Browse the repository at this point in the history
  • Loading branch information
sabina-talipova committed Nov 8, 2023
1 parent 3ca706b commit 22d5471
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions client/src/legacy/LeftAndMain.EditForm.js
Expand Up @@ -107,6 +107,7 @@ $.entwine('ss', function($){

this._super();
},

'from .cms-tabset': {
onafterredrawtabs: function () {

Expand All @@ -126,10 +127,7 @@ $.entwine('ss', function($){
'Admin.VALIDATION_ERRORS_ON_PAGE',
'There are validation errors on this page, please fix them before saving or publishing.'
);
const toastNotificationMessage = ss.i18n._t(
'Admin.VALIDATIONERROR',
'Validation Error'
);

const $editFormErrorBanner = $("#Form_EditForm_error");

// Remove any existing invalid tab icons and screen-reader text
Expand Down Expand Up @@ -159,13 +157,6 @@ $.entwine('ss', function($){
return;
}

// Show a toast notification for DataObject::getCMSValidator() validation errors
if (!this.getValidationErrorShown() && this.hasClass('validationerror')) {
errorMessage(toastNotificationMessage);
// Ensure that this error message popup won't be added more than once
this.setValidationErrorShown(true);
}

// Find tab-pane's with decedent validation .alert's
const $invalidTabPanes = this.find('.tab-pane .alert-danger, .tab-pane .alert.error').closest('.tab-pane');
if (!$invalidTabPanes.length) {
Expand Down Expand Up @@ -213,6 +204,17 @@ $.entwine('ss', function($){
redraw: function() {
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));

if (!this.getValidationErrorShown() && this.hasClass('validationerror')) {
const toastNotificationMessage = ss.i18n._t(
'Admin.VALIDATIONERROR',
'Validation Error'
);

errorMessage(toastNotificationMessage);
// Ensure that this error message popup won't be added more than once
this.setValidationErrorShown(true);
}

// Force initialization of tabsets to avoid layout glitches
this.add(this.find('.cms-tabset')).redrawTabs();
this.find('.cms-content-header').redraw();
Expand Down
3 changes: 3 additions & 0 deletions code/LeftAndMain.php
Expand Up @@ -867,6 +867,9 @@ public function redirect($url, $code = 302)
if ($this->getRequest()->getHeader('X-Pjax') && !$response->getHeader('X-Pjax')) {
$response->addHeader('X-Pjax', $this->getRequest()->getHeader('X-Pjax'));
}
if ($this->getRequest()->getHeader('X-Status') && !$response->getHeader('X-Status')) {
$response->addHeader('X-Status', $this->getRequest()->getHeader('X-Status'));
}
$newResponse = new LeftAndMain_HTTPResponse(
$response->getBody(),
$response->getStatusCode(),
Expand Down

0 comments on commit 22d5471

Please sign in to comment.