Enqueue Scripts and Styles for advance_select Select2 from RWMB
Support › MB Frontend Submission › Enqueue Scripts and Styles for advance_select Select2 from RWMB
- This topic has 3 replies, 2 voices, and was last updated 4 weeks ago by
Peter.
-
AuthorPosts
-
May 20, 2025 at 5:41 PM #48292
pluginoven
ParticipantWe need to enqueue the same styles and scripts that Metabox does when displaying a select_advanced field (Select2) on the front end. We tried calling RWMB_Select_Advanced_Field::admin_enqueue_scripts() but the rwmb variable is not defined. We tried to load in the official select2 css and script, but it dose not match the version that RWMB renders.
Therefore this thread: is there an official way to trigger Metabox to enqueue the nessary scripts and styles for the select_advanced field without having to place a front end form and then hide it (which is not an accessibility conform option).
If required, we can get into the why this is needed, but all we need is to trigger the same load sequence.
May 20, 2025 at 10:39 PM #48295Peter
ModeratorHello,
If you don't use the frontend form in the frontend, there isn't any option to enqueue any field scripts (JS, CSS) in the frontend. I think there is no reason to do so.
You can simply download the Select2 library to your project and enqueue it in the frontend to use a similar feature of select advanced field for your select field.May 20, 2025 at 11:06 PM #48297pluginoven
ParticipantHello Peter, thank you for your response. Just some thoughts:
If you don't use the frontend form in the frontend, there isn't any option to enqueue any field scripts (JS, CSS) in the frontend. I think there is no reason to do so.
OK. Imagine if you will that we use metabox to define a complex form and this form allows users to fill this out and submit it from the front end using a plugin like MB Frontend Submission.
Now imagine that some of these fields are used later, on another page that allows users to search and filter using our pre-built form fields. One of them, for the sake of imagination is a language field using advanced_select. Well! we now have a reason to render this form field on the front end, but not as a submission form, oh no, but form that is used as a filter! Can you imagine that? That might be just one reason to do so. Let me know if you need more reasons. I have three more.
You can simply download the Select2 library to your project and enqueue it in the frontend to use a similar feature of select advanced field for your select field.
I refer you to the first post in the thread, right around the part that reads:
We tried to load in the official select2 css and script, but it dose not match the version that RWMB renders.
I invite you to compare the select2 field that meta-box renders next to the standard select2 field and maybe then you can see the difference. For example using a 'textbox' element for the search field rather than an li/span element as in the case of a metabox select2 rendered field.
May 21, 2025 at 10:53 PM #48305Peter
ModeratorHello,
Thanks for the details. From Meta Box's perspective, we don't support loading the field scripts in the frontend if there is no frontend form. If you create your own form in the frontend, you can create custom code to customize the select2 field based on your requirements.
I will also forward this request to the development team to consider supporting this case. I will let you know if it will be added to the development queue. -
AuthorPosts
- You must be logged in to reply to this topic.