Pass isFirstField attrib, allow prevent of default focus()

This commit is contained in:
Sam Georges 2014-09-10 19:29:02 +10:00
parent 3d36e65a55
commit 73200606bc
1 changed files with 8 additions and 5 deletions

View File

@ -202,15 +202,18 @@ if (window.jQuery === undefined)
* Focus fields with errors
*/
if (data['X_OCTOBER_ERROR_FIELDS']) {
var foundField = false
var isFirstInvalidField = true
$.each(data['X_OCTOBER_ERROR_FIELDS'], function(fieldName, fieldMessages){
var fieldElement = form.find('[name="'+fieldName+'"], [name$="['+fieldName+']"]').filter(':enabled').first()
if (fieldElement.length > 0) {
if (!foundField) {
fieldElement.focus()
foundField = true
var _event = jQuery.Event('ajaxInvalidField')
$(window).trigger(_event, [fieldElement, fieldName, fieldMessages, isFirstInvalidField])
if (isFirstInvalidField) {
if (!_event.isDefaultPrevented()) fieldElement.focus()
isFirstInvalidField = false
}
$(window).trigger('ajaxInvalidField', [fieldElement, fieldName, fieldMessages])
}
})
}