Require Catalog Before Saving Post

Topics: ASP.NET 2.0
May 17, 2011 at 11:30 PM
Edited May 17, 2011 at 11:32 PM

How do i go about requiring the editor to choose a category (or a tag for that matter) before they can save a draft or publish a post?

Coordinator
May 18, 2011 at 7:49 AM

Assuming you're using BE 2.0, you could modify Add_entry.aspx in the /admin/Posts folder.  In there is JavaScript that fires to save the post to the server.  You could add validation that checks to make sure at least one category is selected or one tag is selected.  Here's some code (untested) that would go above "var date = ....."

..... new code start .....
if
($.trim(cats).length === 0 && $.trim(tags).length === 0) { alert('Select at least one category or enter at least one tag.); return false; }
..... new code end .....
...... existing code ......
var
date = document.getElementById('<%=txtDate.ClientID %>').value; var time = document.getElementById('<%=txtTime.ClientID %>').value;
May 18, 2011 at 4:27 PM

I use BE2.  Adding the code doesn't allow me to save the post.  I will try to use some variation of this.  Thanks!

May 18, 2011 at 11:33 PM
Edited May 18, 2011 at 11:46 PM

That's a good point and another top answer from Ben, that was on my to do list.

Works a treat, it's just a typo, missing comma that is causing any problem.

alert('Select at least one category or enter at least one tag.');

PS

Forgot to mention to change the AND to an OR in the if test.

May 19, 2011 at 12:13 AM

Nice and clean.  Thanks so much!