FIX for #5410 to help focus errors occurring on tabs within GridField controlled DataObjects (et al).

Tidy up Entwine logic for selecting tabs containing errors
This commit is contained in:
Patrick Nelson 2016-04-27 20:57:58 -07:00
parent 264d7e8ffe
commit 693408330b
2 changed files with 39 additions and 8 deletions

View File

@ -46,6 +46,14 @@
ChangeTrackerOptions: {
ignoreFieldSelector: '.no-change-track, .ss-upload :input, .cms-navigator :input'
},
/**
* Variable: ValidationErrorShown
* Boolean for tracking whether a validation error has been already been shown. Used because tabs can
* sometimes be inadvertently initialised multiple times, but we don't want duplicate messages
* (Boolean)
*/
ValidationErrorShown: false,
/**
* Constructor: onmatch
@ -77,23 +85,44 @@
}
}
// Reset error display
this.setValidationErrorShown(false);
// TODO
// // Rewrite # links
// html = html.replace(/(<a[^>]+href *= *")#/g, '$1' + window.location.href.replace(/#.*$/,'') + '#');
//
// // Rewrite iframe links (for IE)
// html = html.replace(/(<iframe[^>]*src=")([^"]+)("[^>]*>)/g, '$1' + $('base').attr('href') + '$2$3');
// Show validation errors if necessary
if(this.hasClass('validationerror')) {
// Ensure the first validation error is visible
var tabError = this.find('.message.validation, .message.required').first().closest('.tab');
$('.cms-container').clearCurrentTabState(); // clear state to avoid override later on
tabError.closest('.ss-tabset').tabs('option', 'active', tabError.index('.tab'));
}
this._super();
},
'from .cms-tabset': {
onafterredrawtabs: function () {
// Show validation errors if necessary
if(this.hasClass('validationerror')) {
// Ensure the first validation error is visible
var tabError = this.find('.message.validation, .message.required').first().closest('.tab');
$('.cms-container').clearCurrentTabState(); // clear state to avoid override later on
// Attempt #1: Look for nearest .ss-tabset (usually nested deeper underneath a .cms-tabset).
var $tabSet = tabError.closest('.ss-tabset');
// Attempt #2: Next level in tab-ception, try to select the tab within this higher level .cms-tabset if possible
if (!$tabSet.length) {
$tabSet = tabError.closest('.cms-tabset');
}
if ($tabSet.length) {
$tabSet.tabs('option', 'active', tabError.index('.tab'));
} else if (!this.getValidationErrorShown()) {
// Ensure that this error message popup won't be added more than once
this.setValidationErrorShown(true);
errorMessage(ss.i18n._t('ModelAdmin.VALIDATIONERROR', 'Validation Error'));
}
}
}
},
onremove: function() {
this.changetracker('destroy');
this._super();

View File

@ -1450,6 +1450,8 @@ jQuery.noConflict();
}
}
});
this.trigger('afterredrawtabs');
},
/**