Skip to content

Commit a8748ee

Browse files
Remove jQuery from the user search form in admin page (#29151)
- Switched to plain JavaScript - Tested the form and it works as before --------- Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 6fad2c8 commit a8748ee

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

web_src/js/features/admin/users.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1-
import $ from 'jquery';
2-
31
export function initAdminUserListSearchForm() {
42
const searchForm = window.config.pageData.adminUserListSearchForm;
53
if (!searchForm) return;
64

7-
const $form = $('#user-list-search-form');
8-
if (!$form.length) return;
5+
const form = document.querySelector('#user-list-search-form');
6+
if (!form) return;
97

10-
$form.find(`button[name=sort][value=${searchForm.SortType}]`).addClass('active');
8+
for (const button of form.querySelectorAll(`button[name=sort][value="${searchForm.SortType}"]`)) {
9+
button.classList.add('active');
10+
}
1111

1212
if (searchForm.StatusFilterMap) {
1313
for (const [k, v] of Object.entries(searchForm.StatusFilterMap)) {
1414
if (!v) continue;
15-
$form.find(`input[name="status_filter[${k}]"][value=${v}]`).prop('checked', true);
15+
for (const input of form.querySelectorAll(`input[name="status_filter[${k}]"][value="${v}"]`)) {
16+
input.checked = true;
17+
}
1618
}
1719
}
1820

19-
$form.find(`input[type=radio]`).on('click', () => {
20-
$form.trigger('submit');
21-
return false;
22-
});
21+
for (const radio of form.querySelectorAll('input[type=radio]')) {
22+
radio.addEventListener('click', () => {
23+
form.submit();
24+
});
25+
}
2326

24-
$form.find('.j-reset-status-filter').on('click', () => {
25-
$form.find(`input[type=radio]`).each((_, e) => {
26-
const $e = $(e);
27-
if ($e.attr('name').startsWith('status_filter[')) {
28-
$e.prop('checked', false);
27+
const resetButtons = form.querySelectorAll('.j-reset-status-filter');
28+
for (const button of resetButtons) {
29+
button.addEventListener('click', (e) => {
30+
e.preventDefault();
31+
for (const input of form.querySelectorAll('input[type=radio]')) {
32+
if (input.name.startsWith('status_filter[')) {
33+
input.checked = false;
34+
}
2935
}
36+
form.submit();
3037
});
31-
$form.trigger('submit');
32-
return false;
33-
});
38+
}
3439
}

0 commit comments

Comments
 (0)