Enqueue Scripts and Styles for advance_select Select2 from RWMB

Support MB Frontend Submission Enqueue Scripts and Styles for advance_select Select2 from RWMB

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #48292
    pluginovenpluginoven
    Participant

    We 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.

    #48295
    PeterPeter
    Moderator

    Hello,

    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.

    #48297
    pluginovenpluginoven
    Participant

    Hello 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.

    #48305
    PeterPeter
    Moderator

    Hello,

    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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.