• Resolved andyt1980

    (@andyt1980)


    Hi,
    Is there any way to make an Optgroup Select field a required field?An example of an optgroup field is shown here: https://select2.org/getting-started/basic-usage
    It has headings like ‘Alaskan/Hawaiian Time Zones’

    Is this possible to achieve with your plugin and CF7?. 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. Also, the field needs to be required. Alternatively if it was possible to disable certain options and style those as headings that could also work, as shown in the bottom example here: https://select2.org/options

    Any help much appreciated.

    • This topic was modified 10 months, 1 week ago by andyt1980.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    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.

    Thread Starter andyt1980

    (@andyt1980)

    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,

    Plugin Author Aurovrata Venet

    (@aurovrata)

    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

    Thread Starter andyt1980

    (@andyt1980)

    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?

    Plugin Author Aurovrata Venet

    (@aurovrata)

    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.

    Thread Starter andyt1980

    (@andyt1980)

    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 10 months, 1 week ago by andyt1980.
    Plugin Author Aurovrata Venet

    (@aurovrata)

    you have a mistake on line 30, you’re opening an optgroup element which you are closing as an option

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Optgroup – Required Field’ is closed to new replies.