Created
September 13, 2017 09:00
-
-
Save GeekaholicLin/9fc6bd747a477d84ffc4a340880f5039 to your computer and use it in GitHub Desktop.
[angular-validation] Focus and scrollTo invalid field in Form,making non-input field under consideration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Edited by Geekaholic */ | |
/* For scrollTo invalid form field*/ | |
let timer = null; | |
$validationProvider.invalidCallback = function(element) { | |
element.closest('.form-group').addClass('has-error'); | |
if(!timer){ | |
timer = setTimeout(function () { | |
let isEditing = angular.element('input:focus')[0];//是否正在编辑,用户体验 | |
if(!isEditing){ | |
let offset = angular.element('.form-group.has-error').offset(); | |
window.scrollTo(offset.left,offset.top); | |
element.closest('form').find('.form-group.has-error input')[0].focus(); | |
} | |
clearTimeout(timer); | |
timer = null; | |
},300); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment