PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Option groups on dropdown menu

  1. antonsamper
    Member

    Is there a way to create option groups on dropdown menus? e.g.

    <optgroup label="Design Services">
         <option>website design</option>
         <option>icon design</option>
         <option>iPhone/iPad design</option>
         <option>web application design</option>
         <option>some help</option>
    </optgroup>
    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  2. Currently there's no way to do this within the form editor. You may be able to add the grouping using jQuery in your page template though.

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  3. antonsamper
    Member

    yeah definitely, i was just wondering if i was missing a trick as i could find it, it's not essential at the moment anyway

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  4. I'm sure that's something we will add in the future. I do know it's been discussed around here as an option.

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  5. +1 for optgroup :)

    Posted 13 years ago on Wednesday April 13, 2011 | Permalink
  6. remotecontroldesign
    Member

    +1 !
    Indeed. Optgroup is a must feature for managing very long lists!

    Posted 12 years ago on Monday September 12, 2011 | Permalink
  7. +1 indeed. It's only just popped up for me but, yes - would be very useful in the future. Thanks!

    Posted 12 years ago on Monday October 31, 2011 | Permalink
  8. Optgroup is a feature we still plan on adding in the future. So it is on our to do list. We will never be done enhancing and refining Gravity Forms. There is no finish line.

    Posted 12 years ago on Monday October 31, 2011 | Permalink
  9. hello
    Member

    Need optgroup ASAP!

    Select State or Province
    United States
    -
    -
    -
    Canada
    -
    -
    -

    Posted 12 years ago on Wednesday February 1, 2012 | Permalink
  10. Richard Vav
    Administrator

    It would be great to have this built-in, in the meantime you can accomplish it using a filter.

    Add a drop down to your form but delete all but one of the options then save your form taking note of the form and field id's.

    Next open up your themes functions file and paste in the following not forgetting to update the form and field ids to match the ones from your form and drop down. You will also want to edit the option values and labels (on line 5) and add in as many options and optgroups as you require.

    add_filter('gform_field_content', 'modify_field', 10, 5);
    function modify_field($modify_html, $field){
        if($field['formId'] == 11){
        if($field['id'] == 5){$modify_html = str_replace("<option value='First Choice' >First Choice</option>",
    "<option value='' ></option><optgroup label='Swedish Cars'><option value='volvo'>Volvo</option><option value='saab'>Saab</option></optgroup><optgroup label='German Cars'><option value='vw'>VW</option><option value='audi'>Audi</option></optgroup>",$modify_html);}
    	}
        return $modify_html;
    }
    Posted 12 years ago on Saturday February 11, 2012 | Permalink
  11. +1 for optgroup!

    Posted 11 years ago on Wednesday June 6, 2012 | Permalink
  12. I've been trying to use richardvav's method with no luck. I've got my form id and field id (1 & 7), but the dropdown only shows "First Choice". Has any one had any luck with getting option groups using this (or any other) method?

    UPDATE:
    The form & field id that is richardvav refers to is not the CSS id, but rather an id assigned by GForms that you can find in in the admin area (on your form, up towards the top of each field is the field id, and you can find the form id on the form settings page. It seems like a silly thing, but I had just assumed CSS id :).

    Works great now that I've made that change. Thanks richardvav for sharing!

    Posted 11 years ago on Thursday October 4, 2012 | Permalink

This topic has been resolved and has been closed to new replies.