mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #5412 from patricknelson/issue-5410-error-tab-focus
FIX for #5410 to help focus errors occuring on tabs within GridField controlled DataObjects (et al).
This commit is contained in:
commit
426995cfa6
@ -46,6 +46,14 @@
|
|||||||
ChangeTrackerOptions: {
|
ChangeTrackerOptions: {
|
||||||
ignoreFieldSelector: '.no-change-track, .ss-upload :input, .cms-navigator :input'
|
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
|
* Constructor: onmatch
|
||||||
@ -77,23 +85,44 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset error display
|
||||||
|
this.setValidationErrorShown(false);
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// // Rewrite # links
|
// // Rewrite # links
|
||||||
// html = html.replace(/(<a[^>]+href *= *")#/g, '$1' + window.location.href.replace(/#.*$/,'') + '#');
|
// html = html.replace(/(<a[^>]+href *= *")#/g, '$1' + window.location.href.replace(/#.*$/,'') + '#');
|
||||||
//
|
//
|
||||||
// // Rewrite iframe links (for IE)
|
// // Rewrite iframe links (for IE)
|
||||||
// html = html.replace(/(<iframe[^>]*src=")([^"]+)("[^>]*>)/g, '$1' + $('base').attr('href') + '$2$3');
|
// 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();
|
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() {
|
onremove: function() {
|
||||||
this.changetracker('destroy');
|
this.changetracker('destroy');
|
||||||
this._super();
|
this._super();
|
||||||
|
@ -1450,6 +1450,8 @@ jQuery.noConflict();
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.trigger('afterredrawtabs');
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user