Home Forums Add-ons Flexible Content Field Select2 for choosing Flexible Content Fields? Reply To: Select2 for choosing Flexible Content Fields?

  • Hi @alicam

    I’m afraid this is hard to achieve. You need advanced HTML and Javascript code to do it. If you don’t know how to code, you can always submit a feature request here or hire a developer to help you out with it.

    Basically, you can use the acf/render_field action to add the select2 field and then use the acf/input/admin_footer action to add the Javascript needed to monitor the clicks of the select2 field.

    When someone clicked the option, you need to add the flexible content just like when you clicked the Add Row button. You can emulate the click like this (you can try it on the JS console window):

    jQuery('.acf-field-1234567890abc .button-primary').click();
    jQuery('.acf-field-1234567890abc .acf-fc-popup [data-layout="flexible_layout_name"]').click();

    Where “acf-field-1234567890abc” is the field class (based on field key) and “flexible_layout_name” is the layout name.

    I hope this makes sense 🙂