smartmix
2/14/2017 - 1:05 PM

Mostra e nascondi pods field. Da aggiungere al file function.php http://pods.io/forums/topic/conditional-fields/

Mostra e nascondi pods field. Da aggiungere al file function.php

http://pods.io/forums/topic/conditional-fields/


/*
*  Pod { Conditional Logic
*
*  @description: hide / show fields based on a "trigger" field as per:
*  http://www.elliotcondon.com/conditional-logic-for-advanced-custom-fields/
*  
*/

function my_conditional_logic() {

?>	
	 
	<style type='text/css'>
		.pods-form-ui-row-name-nuemero, 
		.pods-form-ui-row-name-hero-image {
			display: none;
		}
	</style>
	<script type="text/javascript">
	(function($){
		
		
		/*
		*  hide_fields
		*
		*  @description: a small function to hide all the conditional fields
		*  @created: 17/07/12
		*/
		
		function hide_fields()	{
			$('.pods-form-ui-row-name-nuemero, .pods-form-ui-row-name-hero-image').hide();
		}
		
		
		/*
		*  - We use $(document).ready, but is there something more targeted like ACF example
		*/
		
		$(document).ready(function() {
		//$(document).live('acf/setup_fields', function(e, postbox){
			
			// trigger change on the select field to show selected field
			$('.pods-form-ui-row-name-hero-type select').trigger('change');
			
		});
		
		
		/*
		*  Hero Type change
		*/
		
		$('.pods-form-ui-row-name-hero-type select').live('change', function(){
			// vars
			var value = $(this).val();
					
			// hide all fields
			hide_fields();
			
			// show the selected field
			if( value == "image" )
			{
				$('.pods-form-ui-row-name-hero-image').show();
			}
			else if( value == "video" )
			{
				$('.pods-form-ui-row-name-hero-video').show();
			}
			
		});
		
	
	})(jQuery);
	</script>
	
<?php

}

/*
*  These filter/action hooks work, but there must be a smarter/Pod specific hook?
*/

add_filter('admin_head', 'my_conditional_logic'); //works
//add_action('wp_loaded', 'my_conditional_logic'); // works