Home › Forums › Backend Issues (wp-admin) › I have JS in ACF fields working but how about only when a tab is opened? › Reply To: I have JS in ACF fields working but how about only when a tab is opened?
So I fixed this myself with two new conditions in a custom JS file that uses jquery within the WP admin.
// run the code when the specific tab of the form group is clicked on
jQuery(document).on('click','*[data-key="field_123456789"]', function(event){
runCustomCodeFunction();
});
// also run my code if the page loads and this tab is visible (it isn't by default as it isn't the first tab)
if ( jQuery(".acf-field-123456789:visible").length > 0 ) {
runCustomCodeFunction();
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.