Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. (function($) {
  2.  
  3. acf.add_action('ready', function( $el ){
  4.  
  5. //Identify the field you want to check against.
  6. //Use a class to handle scenarios involving repeater / flexible content where multiple instances exist
  7. var $field = $('.example input');
  8.  
  9. $field.on('change', function (evt) {
  10.  
  11. //Comparing against taxonomy field values to determine which other fields to show / hide
  12. switch($(this).val()) {
  13. case '27':
  14. //A semi-strange "up over down" jQuery to ensure if inside a repeater / flexibl content you show/hide only the desired field
  15. $(this).closest(".example").siblings(".conditional-display").removeClass("hidden-by-conditional-logic");
  16. break;
  17. default:
  18. //All other states, lets ensure they are hidden
  19. $(this).closest(".example").siblings(".conditional-display").addClass("hidden-by-conditional-logic");
  20. }
  21.  
  22. });
  23.  
  24. //On initial page load - ACF data may indicate that a field should be shown instead of hidden
  25. //Each ensures it craws for all repeaters / flexible content
  26. $field.each(function( index ) {
  27. if ($(this).val() == '27') {
  28. $(this).closest(".example").siblings(".conditional-display").removeClass("hidden-by-conditional-logic");
  29. }
  30. });
  31.  
  32. });
  33.  
  34. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement