NEW Open first tab with validation errors

This commit is contained in:
Ingo Schommer 2012-07-18 16:49:23 +02:00
parent 3156e75548
commit 09067cc8dd
2 changed files with 29 additions and 0 deletions

View File

@ -88,6 +88,11 @@
if(this.hasClass('validationerror')) {
// TODO validation shouldnt need a special case
statusMessage(ss.i18n._t('ModelAdmin.VALIDATIONERROR', 'Validation Error'), 'bad');
// Ensure the first validation error is visible
var firstTabWithErrors = this.find('.message.validation:first').closest('.tab');
$('.cms-container').clearCurrentTabState(); // clear state to avoid override later on
firstTabWithErrors.closest('.tabset').tabs('select', firstTabWithErrors.attr('id'));
}
// Move navigator to preview if one is available.

View File

@ -473,6 +473,30 @@ jQuery.noConflict();
}
},
/**
* Remove any previously saved state.
*
* Parameters:
* (String) url Optional (sanitized) URL to clear a specific state.
*/
clearTabState: function(url) {
if(typeof(window.sessionStorage)=="undefined") return;
var s = window.sessionStorage;
if(url) {
s.removeItem('tabs-' + url);
} else {
for(var i=0;i<s.length;i++) s.removeItem(s.key(i));
}
},
/**
* Remove tab state for the current URL.
*/
clearCurrentTabState: function() {
this.clearTabState(this._tabStateUrl());
},
_tabStateUrl: function() {
return History.getState().url
.replace(/\?.*/, '')