https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39616
--- Comment #2 from Angela Berrett <[email protected]> --- jQuery to add a vendor ID search to the main Acquisitions page. In case anyone else would like this. Also adding to the jQuery wiki. $(document).ready(function() { // Only run on the acquisitions page with the vendor search form if ($('#acqui_acqui_home_order').length || $('form[name="findsupplier"]').length) { // Add Vendor ID search field and button - MAIN CONTENT version var vendorIdSearchHTML = ` <li style="display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin: 5px 0;"> <label for="vendor_id_search" style="white-space: nowrap;">Vendor ID:</label> <input type="text" id="vendor_id_search" name="vendor_id_search" size="25" style="flex: 1; min-width: 150px; max-width: 300px;" /> <button type="button" id="search_by_vendor_id" class="btn btn-primary" style="white-space: nowrap;"> Search by ID </button> </li> `; // Target the MAIN CONTENT form, not the header // Explicitly exclude header forms var $mainForm = $('#acqui_acqui_home_order form[name="findsupplier"]').not('#header_search form'); // If that doesn't work, try finding forms NOT in the header if (!$mainForm.length) { $mainForm = $('main form[name="findsupplier"], #main form[name="findsupplier"], .main form[name="findsupplier"]').not('#header_search form, header form'); } // Last resort: find all findsupplier forms, exclude header, and use the last one if (!$mainForm.length) { var $allForms = $('form[name="findsupplier"]').not('#header_search form, header form, .navbar form'); $mainForm = $allForms.last(); } // Add to MAIN CONTENT if ($mainForm.length) { // Find supplier input in THIS specific form var $supplierInput = $mainForm.find('input[name="supplier"]'); console.log('Supplier input in main form found:', $supplierInput.length); if ($supplierInput.length) { var $supplierLi = $supplierInput.closest('li'); console.log('Supplier li found:', $supplierLi.length); if ($supplierLi.length) { $supplierLi.after(vendorIdSearchHTML); console.log('Added after supplier li in main form'); } else { // No li, add after parent or try wrapping in div var $parent = $supplierInput.parent(); var divHTML = '<div style="margin: 10px 0;">' + '<label for="vendor_id_search_main">Vendor ID:</label>' + '<input type="text" id="vendor_id_search_main" name="vendor_id_search" size="25" />' + '<button type="button" id="search_by_vendor_id" class="btn btn-primary" style="margin-left: 10px;">Search by ID</button>' + '</div>'; $parent.after(divHTML); console.log('Added after supplier parent in main form (no li)'); } } else { // Find any ul in this form and append var $ul = $mainForm.find('ul').first(); console.log('UL in main form found:', $ul.length); if ($ul.length) { $ul.append(vendorIdSearchHTML); console.log('Appended to ul in main form'); } } } // Handle Search by ID button click (works for both main and header buttons) $(document).on('click', '#search_by_vendor_id, .search_by_vendor_id', function() { console.log('Search by ID clicked'); // Find the vendor ID input - it should be near the button var $vendorIdInput = $(this).siblings('input[name="vendor_id_search"]'); // If not a sibling, try finding by ID (check both main and header) if (!$vendorIdInput.length) { $vendorIdInput = $('#vendor_id_search, #vendor_id_search_main, #vendor_id_search_header'); } console.log('Found input fields:', $vendorIdInput.length); var vendorId = $vendorIdInput.val(); console.log('Raw vendor ID value:', vendorId); if (vendorId) { vendorId = vendorId.trim(); } if (!vendorId || vendorId === '') { alert('Please enter a Vendor ID'); return; } console.log('Searching for vendor ID:', vendorId); // Navigate to the vendor page by ID window.location.href = '/cgi-bin/koha/acqui/supplier.pl?booksellerid=' + vendorId; }); // Allow Enter key in the Vendor ID field to trigger search (both main and header) $(document).on('keypress', '#vendor_id_search, #vendor_id_search_main, #vendor_id_search_header', function(e) { if (e.which === 13) { // Enter key e.preventDefault(); $('#search_by_vendor_id').click(); } }); } else { console.log('Not on acquisitions page'); } }); I tried adding the search to the header as well but it was messy and didn't work. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug. _______________________________________________ Koha-bugs mailing list [email protected] https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
