Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@


/**
* If var is true, focus element when validate end
* @type {boolean}
* collect elements for focus
* @type {Object}
***private variable
*/
var isFocusElement = false;
var focusElements = {};


/**
Expand Down Expand Up @@ -520,7 +520,6 @@
*/
watch();

isFocusElement = false;
ctrl.$setViewValue('');
ctrl.$setPristine();
ctrl.$setValidity(ctrl.$name, undefined);
Expand All @@ -543,10 +542,6 @@
var value = ctrl.$viewValue,
isValid = false;

if (index === 0) {
isFocusElement = false;
}

isValid = checkValidation(scope, element, attrs, ctrl, validation, value);

if (attrs.validMethod === 'submit') {
Expand All @@ -570,11 +565,19 @@

}

// Focus first input element when submit error #11
if (!isFocusElement && !isValid) {
isFocusElement = true;
element[0].focus();
}
var setFocus = function(isValid) {
if(isValid) {
delete focusElements[index];
} else {
focusElements[index] = element[0];

$timeout(function() {
focusElements[Math.min.apply(null, Object.keys(focusElements))].focus();
}, 0);
}
};

isValid.constructor === Object ? isValid.then(setFocus) : setFocus(isValid);
});

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validation.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 16 additions & 13 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@


/**
* If var is true, focus element when validate end
* @type {boolean}
* collect elements for focus
* @type {Object}
***private variable
*/
var isFocusElement = false;
var focusElements = {};


/**
Expand Down Expand Up @@ -228,7 +228,6 @@
*/
watch();

isFocusElement = false;
ctrl.$setViewValue('');
ctrl.$setPristine();
ctrl.$setValidity(ctrl.$name, undefined);
Expand All @@ -251,10 +250,6 @@
var value = ctrl.$viewValue,
isValid = false;

if (index === 0) {
isFocusElement = false;
}

isValid = checkValidation(scope, element, attrs, ctrl, validation, value);

if (attrs.validMethod === 'submit') {
Expand All @@ -278,11 +273,19 @@

}

// Focus first input element when submit error #11
if (!isFocusElement && !isValid) {
isFocusElement = true;
element[0].focus();
}
var setFocus = function(isValid) {
if(isValid) {
delete focusElements[index];
} else {
focusElements[index] = element[0];

$timeout(function() {
focusElements[Math.min.apply(null, Object.keys(focusElements))].focus();
}, 0);
}
};

isValid.constructor === Object ? isValid.then(setFocus) : setFocus(isValid);
});

/**
Expand Down