New Discussion: A way to NOT select a category by default?
I want to teach my community of users that they need to select a Category. Can I modify Vanilla so that it doesn't automatically select a default Category? (So that if they didn't choose a Category and tried to post, it would remind them that they need to choose a Category.)
Best Answers
-
hgtonight MVP
The proper way would be to add a validation rule to the discussion model. Something like this:
public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender) { $Sender->Validation->ApplyRule('CategoryID', 'regex:/^\d+$/', 'You must select a category to post into!'); }
That said, I couldn't get it to work for me on 2.0.18.8.
I would just check for the root category in the form values and kill the execution if -1 was the categoryID, ala:
public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender) { if($Sender->EventArguments['FormPostValues']['CategoryID'] == '-1') { echo 'You must select a category to post into!'; die(); } }
Maybe style it up a little better. It is definitely hack-y.
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
5 -
whu606 MVP
See this discussion:
http://vanillaforums.org/discussion/16672/can-i-force-users-to-choose-a-category-in-vanilla-2#latest
Lincoln's fix worked for me then. I'm not sure if it works in 2.0.18.8, but it's worth a go.
7 -
peregrine MVP
Another option that works.... (but the warning message is not intuitive)
$('#Form_CategoryID').prepend("<option value='999'>Select A Category").prop('selectedIndex', 0); it won't let you post unless you select. I like lincoln's solution though.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
5
Answers
Did this javascript not work for you?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Yes, the JS worked for the dropdown, but it still lets me post without choosing a Category. How do I make that a required field?
The proper way would be to add a validation rule to the discussion model. Something like this:
That said, I couldn't get it to work for me on 2.0.18.8.
I would just check for the root category in the form values and kill the execution if -1 was the categoryID, ala:
Maybe style it up a little better. It is definitely hack-y.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
@charliepratt
See this discussion:
http://vanillaforums.org/discussion/16672/can-i-force-users-to-choose-a-category-in-vanilla-2#latest
Lincoln's fix worked for me then. I'm not sure if it works in 2.0.18.8, but it's worth a go.
Another option that works.... (but the warning message is not intuitive)
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.