Trigger invalid on all fields, but only focus the first one. Also pass the messages across.

This commit is contained in:
Sam Georges 2014-09-10 19:11:21 +10:00
parent 0cffb0c934
commit 3d36e65a55

View File

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