Support

Account

Home Forums Backend Issues (wp-admin) conditional logic for relationship field

Helping

conditional logic for relationship field

  • Hi guys!

    I’m sure it’s possible but have a hard time achieving it!
    how can I make the rest of my ACF fields stay hidden until > 0 post object is chosen in my relationship field?
    I started with this but I can only seem to hide them, the show part does not work

    
    function conditional_logic_reviews()
    {
      ?>
      <style type="text/css"> #excerpt, #intro, #text, #conclusion, #rating, #pros, #cons {display: none;} </style>
      <script type="text/javascript">
      (function($){
        
        function hide_fields()
        {
          $('#excerpt, #intro, #text, #conclusion, #rating, #pros, #cons').hide();
        }
        
        $(document).live('acf/setup_fields', function(e, div){
          if( !$("#target-product .values ul.list").has("li").length ) {
            $('#excerpt, #intro, #text, #conclusion, #rating, #pros, #cons').show();
          }
        });
      
      })(jQuery);
      </script>
      <?php
    }
    
    add_action('acf/input/admin_head', 'conditional_logic_reviews');
    
  • HI @boriskamp1991,

    Thanks for the post.

    In this kind of implementation I would recommend you make use of the show_field action but you will need to call this action independently for each field type that you want to show.

    This should be done like so:

    acf.add_action('show_field', function( $field, context )

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘conditional logic for relationship field’ is closed to new replies.