Permalink
Browse files

NEW Open first tab with validation errors

  • Loading branch information...
1 parent 3156e75 commit 09067cc8dd08111af956785f85dc0e690dcc0765 @chillu chillu committed Jul 18, 2012
Showing with 29 additions and 0 deletions.
  1. +5 −0 admin/javascript/LeftAndMain.EditForm.js
  2. +24 −0 admin/javascript/LeftAndMain.js
@@ -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.
@@ -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(/\?.*/, '')

0 comments on commit 09067cc

Please sign in to comment.