MB Conditional logic is compatible with image_select?
Support › MB Conditional Logic › MB Conditional logic is compatible with image_select?
- This topic has 9 replies, 2 voices, and was last updated 8 years, 11 months ago by
Tan Nguyen.
-
AuthorPosts
-
April 21, 2016 at 5:38 PM #2862
buzzmn
ParticipantI 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.
April 23, 2016 at 9:26 AM #2883Tan Nguyen
ParticipantYes, 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; } );
April 25, 2016 at 5:38 PM #2909buzzmn
ParticipantIn 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!April 26, 2016 at 9:50 AM #2915Tan Nguyen
ParticipantHmm, normally, it should works. Seems that it's a bug of new version, we'll try to fix it soon.
Cheers!
April 28, 2016 at 6:39 PM #2943buzzmn
ParticipantIn 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!
May 2, 2016 at 4:19 PM #2979buzzmn
ParticipantHi 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?May 2, 2016 at 10:28 PM #2982Tan Nguyen
ParticipantDear Buzzmn,
The problem happens when the ID structure is changed. We're looking into that bug and will have a patch this week.
Cheers!
May 2, 2016 at 11:14 PM #2983buzzmn
ParticipantThe 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!
May 12, 2016 at 12:54 AM #3056Tan Nguyen
ParticipantDear 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
May 18, 2016 at 10:22 AM #3114Tan Nguyen
ParticipantDear 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/3f39e4b65ef02373677ac221464cf11e273fdf45Cheers!
-
AuthorPosts
- The topic ‘MB Conditional logic is compatible with image_select?’ is closed to new replies.