Listing categories as checkboxes rather than dropdown list
Posted: 09 October 2010 10:10 AM   [ Ignore ]
Wallflower
Rank
Total Posts:  7
Joined  2010-10-08

The documentation shows two methods of showing the entry’s categories, both of which generate a drop-down menu.

Is it possible to generate a (more user-friendly) checkbox list (as on the current EE2 categories tab) - I couldn’t work out the syntax. It would also need to display the currently checked items if you were editing an existing entry.

Thanks for any help - and for a great product.

Clifford

Profile
 
 
Posted: 12 October 2010 07:35 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

This should do the trick:

{categories}
    
<label><input type="checkbox" value="{category_id}" {checked} />{category_name}</label>
{/categories} 
Profile
 
 
Posted: 13 October 2010 01:29 AM   [ Ignore ]   [ # 2 ]
Wallflower
Rank
Total Posts:  7
Joined  2010-10-08

Great - many thanks. I need to add in name=“category[]” to make it write back to database:

{categories}
    
<label><input type="checkbox" name="category[]" value="{category_id}" {checked} />{category_name}</label>
{/categories} 

One more question: is it possible to sort categories alphabetically by title rather than ID?

Profile
 
 
Posted: 13 October 2010 01:34 AM   [ Ignore ]   [ # 3 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Currently, there’s no way to change the sorting on the categories.

Profile
 
 
Posted: 13 January 2011 07:22 PM   [ Ignore ]   [ # 4 ]
Cleans up Nice!
RankRank
Total Posts:  261
Joined  2010-05-25

Hi Rob,

this works well, but can I break out the category groups into separate lists? I have two category groups attached to a channel and when I use the code above, it lists both category groups in one big list. but these two category groups are not really related and it looks weird if they are all in one list.

thanks
Florian

Profile
 
 
Posted: 13 January 2011 07:26 PM   [ Ignore ]   [ # 5 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

You can specify the group_id in the categories tag. Also, you can now specify order_by, too.

{categories group_id="1"}
    
<label><input type="checkbox" name="category[]" value="{category_id}" {checked} />{category_name}</label>
{/categories} 
{categories group_id
="2" order_by="category_name"}
    
<label><input type="checkbox" name="category[]" value="{category_id}" {checked} />{category_name}</label>
{/categories} 
Profile
 
 
Posted: 13 January 2011 07:30 PM   [ Ignore ]   [ # 6 ]
Cleans up Nice!
RankRank
Total Posts:  261
Joined  2010-05-25

brilliant! just what i need.
thank you Rob!!

Profile
 
 
   
 
 
‹‹ Solspace Tag Field      Browser Issue ››