Hi there. This will probably sound silly.
We would like “United States” and “Canada” to remain static and not be clickable in our drop-down menu. Is this possible? Below each are the given states and provinces.
I have searched for quite some time with no solution.
Any help would be appreciated.
Thank you
chrishajer
(Chris (Gravity Forms))
December 18, 2018, 7:56pm
2
Layouts such as those are sometimes referred to as optgroup, something that is not supported in Gravity Forms at this time.
You could disable those choices in the dropdown using JavaScript or jQuery so they are not selectable.
Here’s an example of how to do it. The specifics will need to change for the actual values of your drop down (by ID or by value):
Hi Chris, thank you for getting back to me.
I was not able to get it working using the link you sent over. I did get to learn a little about optgroups though.
I did get it working using the available function here with instructions from another source.
gravity-forms-select-optgroupify.php
<?php
/**
* Filter for GravityForms to group select field choices by a special "optgroup" choice.
*
* Simply add a new choice with a value of 'optgroup' to the dropdown to start a group of options.
* All following choices will be grouped under it using its label for the group.
* Any number of groups can be created, as each optgroup choice will start a new group.
* Supports field placeholder & ungrouped options, but must be before the first group.
*
* This snippet can be added to your theme's functions.php, or a custom plugin.
This file has been truncated. show original
After including the function I included ‘optgroup’ in the ‘value’ field next to the entries I needed to group.
Worked like a charm. Thank you for guiding me forward brother.
Super appreciated.
1 Like