Skip to content

Commit 49f4a33

Browse files
committed
Toggle reset button when post type changes
1 parent 0947ec3 commit 49f4a33

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

assets/css/admin-pull-table.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
}
2020
}
2121

22-
.pull-taxonomy {
22+
.pull-taxonomy,
23+
.dt-reset-filters-button {
2324

2425
&.hide {
2526
display: none;

assets/js/admin-pull.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if ( chooseConnection && choosePostType && form ) {
4545
* When the post type is changed, show/hide the taxonomy fields based on the post type.
4646
*/
4747
jQuery( choosePostType ).on( 'change', ( event ) => {
48+
let shouldHideResetFiltersButton = false;
4849
const selectedPostType =
4950
event.currentTarget.options[ event.currentTarget.selectedIndex ];
5051
if ( selectedPostType ) {
@@ -65,15 +66,35 @@ if ( chooseConnection && choosePostType && form ) {
6566
jQuery( taxonomyField ).addClass( 'hide' );
6667
jQuery( taxonomyField ).removeClass( 'show' );
6768
}
69+
70+
if (
71+
! shouldHideResetFiltersButton &&
72+
'all' !==
73+
taxonomyField.options[
74+
taxonomyField.selectedIndex
75+
].value
76+
) {
77+
shouldHideResetFiltersButton = true;
78+
}
6879
} );
6980
} else {
7081
pullTaxonomies.forEach( ( taxonomyField ) => {
7182
jQuery( taxonomyField ).addClass( 'hide' );
7283
jQuery( taxonomyField ).removeClass( 'show' );
7384
} );
85+
86+
shouldHideResetFiltersButton = true;
7487
}
7588
}
7689
}
90+
91+
if ( shouldHideResetFiltersButton ) {
92+
jQuery( choosePostTypeReset ).addClass( 'hide' );
93+
jQuery( choosePostTypeReset ).removeClass( 'show' );
94+
} else {
95+
jQuery( choosePostTypeReset ).addClass( 'show' );
96+
jQuery( choosePostTypeReset ).removeClass( 'hide' );
97+
}
7798
} );
7899

79100
if ( choosePostTypeBtn ) {

0 commit comments

Comments
 (0)