Community Add Event form, change taxonomy checkboxes

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.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1106048
    indycourses
    Participant

    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() ); ?>’

    #1106610
    Nico
    Member

    Hi 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,
    Nico

    #1107037
    indycourses
    Participant

    Thanks 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);
        });
    });
    #1107138
    Nico
    Member

    Hey 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

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Community Add Event form, change taxonomy checkboxes’ is closed to new replies.