Visible/hidden with id outside group
Support › MB Conditional Logic › Visible/hidden with id outside groupResolved
- This topic has 6 replies, 2 voices, and was last updated 5 years, 7 months ago by
Julien.
-
AuthorPosts
-
March 8, 2019 at 5:43 PM #13617
Julien
ParticipantHello,
I try to have a conditionnal logic with fields in group with an option outside the group.
$meta_boxes[] = array( 'title' => __( 'Test', 'extensa' ), 'post_types' => array( 'extensa-venuerent' ), 'fields' => array( array( 'name' => 'Number', 'id' => "nbr", 'type' => 'select', 'options' => array( '1' => '1', '2' => '2', '3' => '3', '4' => '4', ), ), array( 'name' => 'Title room 1', 'id' => "title_room_1", 'type' => 'text', ), array( 'visible' => array("nbr", '>=', '2'), 'name' => 'Title room 2', 'id' => "title_room_2", 'type' => 'text', ), array( 'visible' => array("nbr", '>=', '3'), 'name' => 'Title room 3', 'id' => "title_room_3", 'type' => 'text', ), array( 'visible' => array("nbr", '>=', '4'), 'name' => 'Title room 4', 'id' => "title_room_4", 'type' => 'text', ), array( 'name' => 'Items', 'id' => 'item', 'type' => 'group', 'clone' => true, 'sort_clone' => true, 'fields' => array( array( 'name' => 'Value room 1', 'id' => "value_room_1", 'type' => 'text', ), array( 'visible' => array("nbr", '>=', '2'), 'name' => 'Value room 2', 'id' => "value_room_2", 'type' => 'text', ), array( 'visible' => array("nbr", '>=', '3'), 'name' => 'Value room 3', 'id' => "value_room_3", 'type' => 'text', ), array( 'visible' => array("nbr", '>=', '4'), 'name' => 'Value room 4', 'id' => "value_room_4", 'type' => 'text', ), ), ), ), );
The fields outside the group with a "visible" option working great, if I choose nbr = 2, I only have title_room_1 and title_room_2 visible but in group, value_room_3 and value_room_4 are always visible.
I don't know if my explanations are clear 🙁
Any clue ? It's possible ?
March 8, 2019 at 6:55 PM #13618Julien
ParticipantI tried to make a custom callback but it's seems doesn't work too.
'visible' => array("my_custom_callback()", true),
and JS
console.log('my custom callback init'); function my_custom_callback(){ console.log('my custom callback test!'); return false; }
In console I can see "My custom callback init" but never "my custom callback test!" and the element with the visible option is always visible.
Something broked with conditionnal logic ? :s
I found a fix in "conditional-logic.js" in the plugin folder.
Line 234 to 236
if ( ! dependentFieldSelector ) { // return; }
If I comment line 235, my condition work.
March 10, 2019 at 8:16 AM #13636Anh Tran
KeymasterHi Charlin,
The problem is when the group is cloneable, the conditions is "scoped" inside the clone only. Think about a situation when you have a group of 2 fields A and B. B is visible when A has a value "a".
What about if we clone this group and have multiple pairs (A,B). A1 has a value "a", then all B will be visible without scoping, which is weird.
I'll try to think about your situation and provide an update for this specific case.
March 10, 2019 at 1:50 PM #13639Julien
ParticipantHi Anh,
I understand if it can't work I can accept it 😉
For the custom callback, it's a bug or not ? I miss something ?
March 11, 2019 at 11:32 AM #13653Anh Tran
KeymasterTo me, it's more likely a bug. Since it still checks for the selector of dependent element. I'll check and fix that.
September 16, 2019 at 10:59 AM #16143Anh Tran
KeymasterHi Charlin,
Just want to let you know that in recent versions of MB Conditional Logic, you're now able to set conditions for fields outside of the group. So, your conditions above will work (I've just tested)!
September 16, 2019 at 2:20 PM #16150Julien
ParticipantHello,
thank you for your following, I will try these next days 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.