MB Conditional logic is compatible with image_select?

Support MB Conditional Logic MB Conditional logic is compatible with image_select?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2862
    buzzmnbuzzmn
    Participant

    I would like to know if the conditional logic is compatible with image_select. I have a selection of layout and I would like to show or hide some textareas depending which layout the user chooses.

    #2883
    Tan NguyenTan Nguyen
    Participant

    Yes, it does works with Image Select. Here is the example

    
    add_filter( 'rwmb_meta_boxes', function( $meta_boxes )
    {
    	$meta_boxes[] = array(
    		'id' => 'brand_product',
    		'title' => 'Brands and Products',
    		'post_types' => array( 'post', 'page' ),
    		'context'	=> 'normal',
    		'priority'	=> 'high',
    		// Conditional Logic can be applied to Meta Box
    		// In this example: Show this Meta Box by default. Hide it when post format is aside
    		'hidden' => array( 'post_format', 'aside' ),
    		'fields' => array(
    			array(
    				'id'       => 'image_select',
    				'name'     => __( 'Layout', 'your-prefix' ),
    				'type'     => 'image_select',
    				// Array of 'value' => 'Image Source' pairs
    				'options'  => array(
    					'left'  => 'http://placehold.it/90x90&text=Left',
    					'right' => 'http://placehold.it/90x90&text=Right',
    					'none'  => 'http://placehold.it/90x90&text=None',
    				),
    				// Allow to select multiple values? Default is false
    				// 'multiple' => true,
    			),
    			array(
    				'id' 	=> 'apple_products',
    				'name'	=> 'Which Apple product that you love?',
    				'type'	=> 'radio',
    				'options' => array(
    					'iPhone' 	=> 'iPhone',
    					'iPad'		=> 'iPad',
    					'Macbook'	=> 'Macbook',
    					'iWatch'	=> 'iWatch'
    				),
    			       'hidden' => array( 'image_select', '!=', 'left' )
    			)
    		)
    	);
    	return $meta_boxes;
    } );
    
    #2909
    buzzmnbuzzmn
    Participant

    In fact I'm using hidden/visible in fields cloned by groups:

    $meta_boxes[] = array(
    		'id'         => 'layout-content',
    		'title'      => 'Contenido',
    		'post_types' => array( 'caso', 'tratamiento' ),
    		'fields'     => array(
    			array(
    				'name'   => 'Añade las filas que desees',
    				'id'     => 'item-row',
    				'type'   => 'group',
    				'clone'  => true,
    				'fields' => array(
    					array(
    						'name'     => 'Esquema',
    						'id'       => 'layout',
    						'required' => true,
    						'type'     => 'image_select',
    						'options'  => array(
    							'textimage' => get_bloginfo('template_url').'/images/settings/layout-textimage.png',
    							'imagetext' => get_bloginfo('template_url').'/images/settings/layout-imagetext.png',
    							'onlytext'  => get_bloginfo('template_url').'/images/settings/layout-text.png',
    							'onlyimage' => get_bloginfo('template_url').'/images/settings/layout-image.png',
    						),
    						'desc'     => 'Si no se escoge ninguna opción por defecto usará el esquema texto a la izquierda e imagen a la derecha'
    					),
    					array(
    						'name'    => 'Texto',
    						'id'      => 'item-text',
    						'type'    => 'textarea',
    						'cols'    => 1,
    						'rows'    => 5,
    						'desc'    => 'Para poder poner negrita se tiene que encapsular el texto entre [negrita][/negrita] (ejemplo: Esto es un [negrita]ejemplo[/negrita].)',
    						'visible' => array( 'layout', 'in', array( 'onlytext', 'textimage', 'imagetext' ) ),
    					),
    					array(
    						'name'      => 'Imágenes',
    						'id'        => 'item-images',
    						'type'      => 'file_advanced',
    						'mime_type' => 'image',
    						'desc'      => 'Las imágenes se mostrarán una debajo de la otra',
    						'visible' => array( 'layout', 'in', array( 'onlyimage', 'textimage', 'imagetext' ) ),
    					),
    				),
    			),
    		),
    	);

    I don't know if the groups or the clone function does affect to the right behavior of the conditional plugin...

    Let me know your opinion.
    Thanks!

    #2915
    Tan NguyenTan Nguyen
    Participant

    Hmm, normally, it should works. Seems that it's a bug of new version, we'll try to fix it soon.

    Cheers!

    #2943
    buzzmnbuzzmn
    Participant

    In fact, I have detected the bug exactly what does: When you have conditional logic combined with cloned groups the fields that have to be hidden or visible are defined by the first element of the cloned groups. It doesn't matter if it's select or image_select... Let me know if I have explained it correct, so you can understand the problem and if it has a easy solution. Meanwhile I would not use the conditional logic, what a pitty...

    Cheers!

    #2979
    buzzmnbuzzmn
    Participant

    Hi again,
    I think the problem is about the IDs of the fields, could I assign different IDs in clones groups as an auto-increment index?

    #2982
    Tan NguyenTan Nguyen
    Participant

    Dear Buzzmn,

    The problem happens when the ID structure is changed. We're looking into that bug and will have a patch this week.

    Cheers!

    #2983
    buzzmnbuzzmn
    Participant

    The bug is created when the id that selects which field to show or hide is named 'layout'. I have changed it and it works!

    Thanks for your attention!

    #3056
    Tan NguyenTan Nguyen
    Participant

    Dear buzzmn, sorry for late reply, I've tried to fix it but it's a Meta Box bug as reported here:

    https://github.com/rilwis/meta-box/issues/860

    Currently, I haven't workaround for this. You can use Radio instead of current Image Select, we'll try to fix this bug on Meta Box soon.

    Sorry again.

    Tan

    #3114
    Tan NguyenTan Nguyen
    Participant

    Dear buzzm,

    We've fixed this bug, please update Group to the latest version, and apply this patch by replace Image Select to the latest version related to this issue:

    https://github.com/rilwis/meta-box/issues/860

    The commit here, you can replace file now if you really need, of course, you can wait for the official release:
    https://github.com/rilwis/meta-box/commit/3f39e4b65ef02373677ac221464cf11e273fdf45

    Cheers!

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘MB Conditional logic is compatible with image_select?’ is closed to new replies.