Eric Babinet
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Found a small bug in the above code. When the page is loaded there may already be a filter selected, so you need to call tg_filter_changed() and category_filter_changed() before the closing </script> tag.
Hi Chris – If the issue is that they can’t both be used simultaneously, rather than hiding the category selector, how about if you disable it when a tag group is selected, and disable the tag group selector if a category is selected. I tried out the following code in post_filter.view.php and it appears to work:
<select name="tg_filter_posts_value" onchange=tg_filter_changed()> <option value=""><?php _e( 'Filter by tag group', 'tag-groups' ); ?></option> <?php foreach ( $data as $term_group => $label ) { printf( '<option value="%s"%s>%s</option>', $term_group, ( '' != $current_term_group && $term_group == $current_term_group ) ? ' selected="selected"' : '', htmlentities( $label, ENT_QUOTES, "UTF-8" ) ); } ?> </select><script> function tg_filter_changed() { var selectedGroup = document.getElementsByName("tg_filter_posts_value")[0].value; if (selectedGroup == "") { document.getElementById("cat").removeAttribute("disabled"); } else { document.getElementById("cat").setAttribute("disabled",""); } return true; } function category_filter_changed() { var selectedGroup = document.getElementById("cat").value; if (selectedGroup == "0") { document.getElementsByName("tg_filter_posts_value")[0].removeAttribute("disabled"); } else { document.getElementsByName("tg_filter_posts_value")[0].setAttribute("disabled",""); } return true; } document.getElementById("cat").setAttribute("onchange","category_filter_changed()"); </script>- This reply was modified 6 years, 10 months ago by Eric Babinet. Reason: add code tag
Viewing 2 replies - 1 through 2 (of 2 total)