Just wanted to know, is it possible to let the user select a category via safecracker, by means of a grouped drop down?

Something like this


Where by , in this case "England" is the parent category, and Avon, Bedfordshire etc are the child categories. Looking to use this for users to choose the category in safecracker, and search via this method in a Low search form.


2 Answers 2


Take a look at this answer on StackOverflow which details how to accomplish nested using jQuery.

  • Thanks for that. I had kind if hopes it would have been possible natively?
    – shorn
    Feb 8, 2013 at 8:17
  • That example shows you how to do this with basic html as well using <optgroup>. The example you posted looked to me like it was using jQuery, hence my jQuery suggestion.
    – Anna_MediaGirl
    Feb 8, 2013 at 15:00

It is possible with the native safecracker {categories} tag, but your milage may vary. you can check if {category_parent} is empty (meaning it is a top category), but there is no nice way to close the optgroup. I've found that not closing the optgroup does work, but haven't tested it in all browsers. Also, for nested categories EE outputs a couple of &nbsp; before the category_name to denote the depth of the category.

Edit: also make sure how u want to use (or need to use) the setting for
"Auto-Assign Category Parents" under Admin > Channel Administration > Global preferences

<select name="category[]" id="categories">
  {if '{category_parent}'==''}
    <optgroup label="{category_name}">
  {if '{category_parent}'!=''}
    <option value="{category_id}"{selected}>{category_name}</option>

// result optgroups :) but not closing optgroup tags

<select name="category[]" id="categories">
  <optgroup label="base1">
  <option value="1" selected="selected">cat1</option>
  <option value="2">cat2</option>
  <optgroup label="base2">
  <option value="7">cat3</option>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.