Over the next few days, I’m going to be releasing a few extensions I’ve written for Navigant.
First on the list is Sarge, a simple extension that adds <optgroup> support to the Drop-down List field type, and lets you specify the value of each option.
Example “Select Options” textarea:
Select an option... =
[optgroup] = Group 1 Option 1 = value_1 Option 2 = value_2 Option 3 = value_3 [/optgroup] Other Option 1 = value_4 Other Option 2 = value_5
Note that specifying each value is optional. If you don’t add an equal sign (=) the option will work just like it would without this extension (the value gets set to the name of the option).
But this extension was too easy to write to wait around for EE 2.
Well that’s easier said by someone who knows what they are doing
I for one wouldn’t have even known what that hook was going on about in the first place let alone know what to code to do anything with it!!
Great extension Brandon, thanks again. I’m sure this will come in handy somewhere along the line for me and I would think for a lot of other users too so thanks for that.
What are people using this extension for? It just affects the Control Panel right? Is it mostly to help the site admins be more organized?
It’s mainly for the people that are writing content.
I’m using it for an upcoming section on NavigantConsulting.com that will replace their existing “biography database” site. When we’re done, the professionals will be able to log into the CMS and update their profile, and one of the fields is a drop-down list where they select their Office Location. That drop-down, thanks to this extension, is organized into two optgroups: International and United States. (See attachment)
It’s also helpful on the templating side… All those options that start with “CA -” have their values set such that {p_office} shows everything but the “CA -” part.
I love this. For example, I always like to show a whole state name in a dropdown, but only store the two-letter code - and this lets me do that easily.
I have a state field where 80% of the entries will be “Michigan”. Any way on the Publish screen to have a default value selected? Would save my client that extra effort of even having to use the dropdown at all.
I love this. For example, I always like to show a whole state name in a dropdown, but only store the two-letter code - and this lets me do that easily.
Glad you like it!
I have a state field where 80% of the entries will be “Michigan”. Any way on the Publish screen to have a default value selected? Would save my client that extra effort of even having to use the dropdown at all.
You could assign Michigan to no value (Michigan = ), and make sure every other option does have a value (including blank rows—or just remove any of those). Not ideal, but that’s probably the only way to do it.
I was sort of thinking of modding this to look for a “* ” at the front of a line (or something similar), which could output selected=“selected” when it draws that row, but I’m just thinking out loud.
Select an option... =
[optgroup] = Group 1 Option 1 = value_1 * Option 2 = value_2 Option 3 = value_3 [/optgroup] Other Option 1 = value_4 Other Option 2 = value_5
OK… I had thought about that but saw a limitation (I’d have no way of knowing if a row further down the line should be selected or not), but I suppose I could have something like that apply only if the fields value is null.
The only issue would be that if you want to select an option without a value, every time you come back to the Edit form you’d have to reselect that option. Although I have a feeling if you’re using the ‘default option’ feature, you probably won’t have any options that have no value to begin with.