mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
After a javascript validation error from a form submission, focus on the first errored field
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.2@69634 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
93c98bf926
commit
67d79a907e
@ -94,6 +94,7 @@ Behaviour.register({
|
||||
|
||||
var error = hasHadFormError();
|
||||
if(!error && fromAnOnBlur) clearErrorMessage(fromAnOnBlur);
|
||||
if(error && !fromAnOnBlur) focusOnFirstErroredField();
|
||||
|
||||
return !error;
|
||||
},
|
||||
|
@ -1,7 +1,9 @@
|
||||
var _CURRENT_FORM;
|
||||
var _FIRST_ERRORED_FIELD = null;
|
||||
|
||||
function initialiseForm(form, fromAnOnBlur) {
|
||||
_CURRENT_FORM = form;
|
||||
_FIRST_ERRORED_FIELD = null;
|
||||
|
||||
if(fromAnOnBlur) {
|
||||
limitValidationErrorsTo(fromAnOnBlur);
|
||||
@ -17,6 +19,13 @@ function hasHadFormError() {
|
||||
return _HAS_HAD_FORM_ERROR || !_ERROR_CACHE;
|
||||
}
|
||||
|
||||
function focusOnFirstErroredField() {
|
||||
try {
|
||||
_FIRST_ERRORED_FIELD.focus();
|
||||
} catch(er) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns group with the correct classname
|
||||
*/
|
||||
@ -251,6 +260,9 @@ function validationError(field,message, messageClass, cacheError) {
|
||||
// Keep a reference to it
|
||||
field.validationMessage = validationMessage;
|
||||
|
||||
// Keep a reference to the first errored field
|
||||
if(field && !_FIRST_ERRORED_FIELD) _FIRST_ERRORED_FIELD = field;
|
||||
|
||||
// Set the attributes
|
||||
validationMessage.className = "message " + messageClass;
|
||||
validationMessage.innerHTML = message;
|
||||
|
Loading…
Reference in New Issue
Block a user