From d8fa9b158090461013294840a49a5e3eab7ce420 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Tue, 13 Feb 2024 16:13:06 +0200 Subject: [PATCH] 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 Co-authored-by: wxiaoguang (cherry picked from commit a8748eedae3518550bd43fd592d206df2bea6bef) Conflicts: web_src/js/features/admin/users.js prefer Gitea version and discard jQuery specific fixes from Forbid jQuery `.prop` and fix related issues (#29832) --- web_src/js/features/admin/users.js | 45 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/web_src/js/features/admin/users.js b/web_src/js/features/admin/users.js index 171e50f9e9..7cac603b5c 100644 --- a/web_src/js/features/admin/users.js +++ b/web_src/js/features/admin/users.js @@ -1,34 +1,39 @@ -import $ from 'jquery'; - export function initAdminUserListSearchForm() { const searchForm = window.config.pageData.adminUserListSearchForm; if (!searchForm) return; - const $form = $('#user-list-search-form'); - if (!$form.length) return; + const form = document.querySelector('#user-list-search-form'); + if (!form) return; - $form.find(`button[name=sort][value=${searchForm.SortType}]`).addClass('active'); + for (const button of form.querySelectorAll(`button[name=sort][value="${searchForm.SortType}"]`)) { + button.classList.add('active'); + } if (searchForm.StatusFilterMap) { for (const [k, v] of Object.entries(searchForm.StatusFilterMap)) { if (!v) continue; - $form.find(`input[name="status_filter[${k}]"][value=${v}]`).checked = true; + for (const input of form.querySelectorAll(`input[name="status_filter[${k}]"][value="${v}"]`)) { + input.checked = true; + } } } - $form.find(`input[type=radio]`).on('click', () => { - $form.trigger('submit'); - return false; - }); - - $form.find('.j-reset-status-filter').on('click', () => { - $form.find(`input[type=radio]`).each((_, e) => { - const $e = $(e); - if ($e.attr('name').startsWith('status_filter[')) { - $e.checked = false; - } + for (const radio of form.querySelectorAll('input[type=radio]')) { + radio.addEventListener('click', () => { + form.submit(); }); - $form.trigger('submit'); - return false; - }); + } + + const resetButtons = form.querySelectorAll('.j-reset-status-filter'); + for (const button of resetButtons) { + button.addEventListener('click', (e) => { + e.preventDefault(); + for (const input of form.querySelectorAll('input[type=radio]')) { + if (input.name.startsWith('status_filter[')) { + input.checked = false; + } + } + form.submit(); + }); + } }