Group and filter rwmb_field_ID_html issue
- This topic has 5 replies, 2 voices, and was last updated 5 years, 2 months ago by
Long Nguyen.
-
AuthorPosts
-
August 13, 2020 at 1:50 PM #21244
LucaBarbi
ParticipantHello! I'm using a clonable gruop to show a large data set on a custom post type admin page and the loading time is dramatically high. I'm trying to prevent the loading of the groups until user click on a button.
To do that I find the filter rwmb_{field_id}_html and I write that piece of code for the called function:
if (isset($_GET['show_products']) and !empty($_GET['show_products'])) { return $field_html; } elseif ($this->counter++ == 0) { return '<a>Mostra i prodotti</a>'; } else { return null; }This solution is working fine, exept for the remove buttons that are seems to be ignored by the filter, so in my page, when the user didn't clicked the button, I have zero group but over two hundreds remove buttons!
How I can fix that problem? I would have something more elegant than hiding remove-clone on css because of the number of that.
August 13, 2020 at 4:04 PM #21250Long Nguyen
ModeratorHi Luca,
We have the extension MB Conditional Logic to show/hide meta boxes, custom fields, or any elements based on other fields’ values. For more information, please follow this documentation https://docs.metabox.io/extensions/meta-box-conditional-logic/.
August 13, 2020 at 4:55 PM #21251LucaBarbi
ParticipantHi Long,
I already tried with the solution you prospect, but the results is similar to set display: none in CSS and this solution doesn't impact on load time.
What I expect to find, is a solution that consent me to completely prevent loading the custom fields until user explicitly make a request for clicking the button (then I retrive the code by an Ajax call).
My only problem whit this solution are the remove buttons, because even if the callable function for the filter rwmb_{field_id}_html return null value, the remove buttons are still on page.
So, how can I prevent the load of the return buttons if the callable function return null?
August 13, 2020 at 5:28 PM #21256LucaBarbi
ParticipantSolved! The remove button is placed on the outer_html!
August 13, 2020 at 5:53 PM #21258LucaBarbi
ParticipantSorry, I believed to find a solution, but didn't work, so my question is still open!
August 15, 2020 at 9:41 PM #21295Long Nguyen
ModeratorHi,
I think you can register the cloneable group field in a separate meta box, then use the filter
rwmb_show_{$meta_box_id}to show/hide this meta box.add_filter( 'rwmb_show_{$meta_box_id}', function( $show, $meta_box ) { if ( true ) { return true; } else { return false; } }, 99, 2 );For more information, please follow this documentation https://docs.metabox.io/filters/#rwmb_show_meta_box_id.
-
AuthorPosts
- You must be logged in to reply to this topic.