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).
For more information and the download, go to http://brandon-kelly.com/apps/sarge/
Enjoy!
Excellent Brandon,
I’m sure a lot of people are going to find that very handy. I’m off to have a play now in case I can use it on anything 😉
Always like to try out every single extension, module and plugin that there is and see how they all work.
Well done private Brandon. Consider yourself a first-class officer. Atteeeeeeeeeen-tion!! 😉
Best wishes,
Mark
I am kind of expecting (hoping) that EE 2 will let you specify the value for each option… We’ll see.
I wouldn’t be surprised… cp.publish.php already uses their input_select_option method to build the list, which accepts a value parameter.
But this extension was too easy to write to wait around for EE 2.
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.
Best wishes,
Mark
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
Thanks for this, and your suggestion.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.