Home › Forums › Calendar Products › Community Events › Community Add Event form, change taxonomy checkboxes
- This topic has 3 replies, 2 voices, and was last updated 8 years ago by Nico.
-
AuthorPosts
-
April 22, 2016 at 11:32 am #1106048indycoursesParticipant
Hi,
I’m wondering if there is a way to customize the way users select the event category. We don’t want to be able to select multiple, as the checkboxes allow. Is there a way to change this to radio buttons or a select?
The function I have found displaying the checkboxes is
‘<?php Tribe__Events__Community__Modules__Taxonomy_Block::instance()->the_category_checklist( get_post() ); ?>’
April 25, 2016 at 7:29 am #1106610NicoMemberHi Roxanne,
Thanks for getting in touch! Interesting question here…
While it’s not possible to customize this output without creating an alternative of your own (which might be a bit of an overkill for this), you can prevent the multiple selection via JavaScript. Just paste this snippet in your theme’s script or insert it via functions.php like this:
/*
* Community Events: limit categories selection to 1
*/
function tribe_community_single_category() { ?><script type="text/javascript">
jQuery(document).ready ( function ( ) {
jQuery('.tribe-events-community-details #event-categories input[type=checkbox]').click ( function ( event ) {
jQuery('.tribe-events-community-details #event-categories input[type=checkbox]').not(this).attr('checked', false);
});
});</script>
<?php
}
add_action('wp_head', 'tribe_community_single_category');
Please let me know if this works for you,
Best,
NicoApril 26, 2016 at 5:53 am #1107037indycoursesParticipantThanks Nico,
That worked, with just a couple little tweaks which are below for reference for others; I switched out “jQuery” for “$” and removed whitespace in a couple spots that prevented the script from working.
It’s not ideal, since this is changing the default and expected behaviour of a checkbox, but it’ll work for now.
$(document).ready( function ( ) { $('.tribe-events-community-details #event-categories input[type=checkbox]').click( function ( event ) { $('.tribe-events-community-details #event-categories input[type=checkbox]').not(this).attr('checked', false); }); });
April 26, 2016 at 9:07 am #1107138NicoMemberHey Roxanne,
Thanks for following up and for sending your version of the code. As you say it’s not ideal as it’s not a good practice to change how default components work but it’s a start. You can change those to radio buttons via JS as well if needed.
I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.
Best,
Nico -
AuthorPosts
- The topic ‘Community Add Event form, change taxonomy checkboxes’ is closed to new replies.