Skip to content

Commit

Permalink
NEW Open first tab with validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Jul 18, 2012
1 parent 3156e75 commit 09067cc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions admin/javascript/LeftAndMain.EditForm.js
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions admin/javascript/LeftAndMain.js
Expand Up @@ -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(/\?.*/, '')
Expand Down

0 comments on commit 09067cc

Please sign in to comment.