Created
September 5, 2015 00:48
-
-
Save colegeissinger/701df3e5be49fc7e5be2 to your computer and use it in GitHub Desktop.
Fixing ACF Pro so the dreded "isArrayLike empty obj error" is avoided
This file contains 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
acf.add_filter('validation_complete', function( json, $form ){ | |
// Return early if there are no errors. | |
// This will avoid the dreded "isArrayLike empty obj error" | |
// https://github.com/jquery/jquery/issues/2242 | |
if ( 0 === json.errors ) { | |
return json; | |
} | |
// show field error messages | |
$.each( json.errors, function( k, item ){ | |
var $input = $form.find('[name="' + item.input + '"]').first(), | |
$field = acf.get_field_wrap( $input ), | |
$tab = $field.prevAll('.acf-field[data-type="tab"]:first'); | |
// does tab group exist? | |
if( ! $tab.exists() ) | |
{ | |
return; | |
} | |
// is this field hidden | |
if( $field.hasClass('hidden-by-tab') ) | |
{ | |
// show this tab | |
$tab.siblings('.acf-tab-wrap').find('a[data-key="' + acf.get_data($tab, 'key') + '"]').trigger('click'); | |
// end loop | |
return false; | |
} | |
// field is within a tab group, and the tab is already showing | |
// end loop | |
return false; | |
}); | |
// return | |
return json; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment