1

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

dropdown

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.

0
1

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

2
  • Thanks for that. I had kind if hopes it would have been possible natively? – shorn Feb 8 '13 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 '13 at 15:00
0

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">
{categories}
  {if '{category_parent}'==''}
    <optgroup label="{category_name}">
  {/if}
  {if '{category_parent}'!=''}
    <option value="{category_id}"{selected}>{category_name}</option>
  {/if}
{/categories}
</select>

// 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>
</select>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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