• Resolved danielhroedentallab

    (@danielhroedentallab)


    Since we have learned that using tags/categories does NOT work with the filter bar, eg
    [tribe_events filter-bar=”yes” view=”photo” tags=”double-arch-dentate,single-arch-dentate,single-arch-edentulous”]

    (Events are limited on right but then nothing works on filter itself)

    I am seeking a way to precheck the radio boxes in the Category section. Unfortunately the element IDs are different each time the page is loaded so this does not work:

    <script>document.getElementById(“tribe-events-filterbar-de5f7594-live-surgery”).checked = true;</script>

    We need to use a wildcard as all instances of the checkbox do at least END the same, in this case “live-surgery”

    I have tried various JS and JQuery with no good result (using inline javascript widget in wpbakery)

    $(“[id$=’live-surgery’]”).click();

    document.querySelectorAll(“[id$=’live-surgery’]”).checked = true;

    etc. Looking for ideas

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Gustavo Bordoni

    (@bordoni)

    Hi @danielhroedentallab,

    After taking a closer look at the code I dug around and made sure that we have a fix for your problem where it will have the tags display.

    I know exactly what the problem actually is, but to solve it for all customers would take a couple days even weeks to properly test and ensure it doesn’t break on any other of the multiple scenarios with have with our customers.

    So I crafted something tailor made for you that will actually help us solve the problem in the future:

    <?php
    add_filter( 'tribe_events_filter_bar_views_v2_1_template_vars_filters', static function ( $filters, $context, $breakpoint_pointer  ) {
    	$shortcode_id = $context->get( 'shortcode' );
    	if ( empty( $shortcode_id ) ) {
    		return $filters;
    	}
    
    	$shortcode = tribe( \Tribe\Events\Pro\Views\V2\Shortcodes\Tribe_Events::class )->get_database_arguments( $shortcode_id );
    
    	$tags = \Tribe__Utils__Array::get( $shortcode, 'tag', [] );
    	if ( empty( $tags ) ) {
    		return $filters;
    	}
    
    	foreach ( $filters as &$filter ) {
    		if ( ! $filter['filter_object'] instanceof \Tribe\Events\Filterbar\Views\V2\Filters\Tag ) {
    			continue;
    		}
    
    		if ( ! is_array( $filter['filter_object']->currentValue ) ) {
    			$filter['filter_object']->currentValue = $tags;
    		} else {
    			$filter['filter_object']->currentValue = array_unique( array_merge( $filter['filter_object']->currentValue, $tags ) );
    		}
    
    		foreach ( $filter['fields'] as &$field ) {
    			if ( in_array( $field['value'], $tags ) && true !== $field['checked'] ) {
    				if ( ! is_int( $filter['selections_count'] ) ) {
    					$filter['selections_count'] = 0;
    				}
    
    				$field['checked'] = true;
    				$filter['selection_count']++;
    			}
    		}
    
    		$filter['selections'] = $filter['filter_object']->get_current_value_for_display();
    	}
    
    	return $filters;
    }, 25, 3 );
    

    The code above can be inserted on your functions.php and it should fix the problem.

    Best Regards,

    Thread Starter danielhroedentallab

    (@danielhroedentallab)

    Thanks! That is EXACTLY what I wanted – and i think others will appreciate this as well when you incorporate it into the main code. We really appreciate the solution!

    You can now see this tag:

    [tribe_events filter-bar=”yes” view=”photo” tags=”double-arch-dentate,single-arch-dentate,single-arch-edentulous”]

    Working here:

    https://www.roedentallab.com/test-page-two/

    Thread Starter danielhroedentallab

    (@danielhroedentallab)

    Not an issue but a limitation is that those items STAY checked if you use that shortcode and this implementation – you cannot uncheck them (which is fine for me, just warning others)

    Plugin Author Gustavo Bordoni

    (@bordoni)

    I am so glad this resolved you problem.

    Side-note, preventing that the items are removed is a intentional behavior, that is why I mentioned that the solution was custom made because Edge Cases like those were not properly tested and resolved.

    Thanks so much for point that out, I will create a internal ticket for us to handle those two items in some capacity.

    Best regards,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘precheck check boxes on filter bar’ is closed to new replies.