Home Forums Backend Issues (wp-admin) “Adding custom javascript to fields,” a “show_field” question


“Adding custom javascript to fields,” a “show_field” question

  • Hello ACF folks.

    I’m fairly new at, “Adding custom javascript to fields,” as detailed in the documentation here ( and could use some help understanding how to best use some of the code on that page.

    Specifically, I am trying to run some code when a specific field appears, conditionally. I am attempting to use “show_field” for this task. The idea is something like, “If field-A has value, check the value of field-A and add placeholder copy based on five different value ranges.”

    Question: The show_field functionality, on the page above, references the following code:

    acf.add_action('show_field', function( $field, context ){
        // context is a string of either 'tab' or 'conditional_logic'
        // do something to $field

    How do I select a “$field” given the structure above? If the field isn’t available yet, how would I reference it with jQuery, or any other way? Everything I have tried has had errors.

    An example below:

    acf.add_action('show_field', function( jQuery('#relevancy1'), conditional_logic ) {...
    This version throws an “undefined” error, which makes sense since the element is not within the HTML, yet. How do I reference the element before it is ready to use?

    Hopefully this makes sense. Thanks for the help!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.