Is this possible to achieve with your plugin and CF7?
sure
I added the select2 class to a dropdown field and it successfully converts it to a select2 field but I couldn’t see a way of adding optgroup labels.
that is a limitation of the CF7 plugin dropdown field.
You can achieve it using the dynamic dropdown field provided with this plugin. The dynamic dropdown has the ability to construct its list of options programmatically using a hook. Just pass your html list of optgroup/option to the filter. You will also need to pass a default value (if you need one). The plugin will then wrap the list in a <select> element that is compatible with what the cf7 plugin expects.
Hi, Thats great, could you advise how I share the HTML with the filter exactly, I presume its after the ‘$data =’ line
Heres what I have so far, I’ve included the optgroup html after the filter code for your reference: https://codefile.io/f/ke9o6tvdjV
Thanks,
no, $data is for your data source as indicated in the filter helper. What the filter returns, $options, is what you need to supply, as a list of html option/optgroup
Hi, I don’t understand what I have to pass to the data variable?
This is the code I have so far: https://codefile.io/f/ke9o6tvdjV
Can you please assist further?
I don’t understand what I have to pass to the data variable?
all the instructions are there in my posts.
I don’t do specific code answers as this is what developers are for. You should hire a developer like myself if you need custom coding.
Hi, I followed one of your video tutorials on youtube and think I am very close now.
Can you see where I have gone wrong here as nothing is being displayed on the front-end except an empty select field: https://codefile.io/f/ke9o6tvdjV
-
This reply was modified 2 years, 4 months ago by
andyt1980.
you have a mistake on line 30, you’re opening an optgroup element which you are closing as an option