commit 551a2945612cfa201d7815fb6c89941d6c54438a
parent f4b7c92abb62157b636a85896d89031a3c40bf4c
Author: breadcat <breadcat@users.noreply.github.com>
Date: Tue, 7 Oct 2025 16:12:16 +0100
Don't steal search submit when on bulk tag page
Diffstat:
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/static/bulk-tag.js b/static/bulk-tag.js
@@ -1,13 +1,18 @@
-// Auto-focus the file range input
-document.getElementById('file_range').focus();
+document.addEventListener('DOMContentLoaded', function () {
+ const fileRangeInput = document.getElementById('file_range');
+ if (!fileRangeInput) return;
-// Update form behavior based on operation selection
-function updateValueField() {
- const operation = document.querySelector('input[name="operation"]:checked').value;
- const valueField = document.getElementById('value');
- const valueLabel = document.querySelector('label[for="value"]');
+ const fileForm = fileRangeInput.closest('form');
+ if (!fileForm) return;
- if (operation === 'add') {
+ function updateValueField() {
+ const checkedOp = fileForm.querySelector('input[name="operation"]:checked');
+ const valueField = fileForm.querySelector('#value');
+ const valueLabel = fileForm.querySelector('label[for="value"]');
+
+ if (!checkedOp || !valueField || !valueLabel) return;
+
+ if (checkedOp.value === 'add') {
valueField.required = true;
valueLabel.innerHTML = 'Value: <span style="color: red;">*</span>';
} else {
@@ -16,20 +21,21 @@ function updateValueField() {
}
}
-// Set up event listeners for radio buttons
-document.querySelectorAll('input[name="operation"]').forEach(radio => {
+// Set up event listeners for radio buttons inside this form
+fileForm.querySelectorAll('input[name="operation"]').forEach(function (radio) {
radio.addEventListener('change', updateValueField);
});
// Initialize on page load
updateValueField();
-// Add form validation
-document.querySelector('form').addEventListener('submit', function(e) {
- const fileRange = document.getElementById('file_range').value.trim();
- const category = document.getElementById('category').value.trim();
- const value = document.getElementById('value').value.trim();
- const operation = document.querySelector('input[name="operation"]:checked').value;
+ // Add form validation ONLY to the fileForm (won't affect the search form)
+ fileForm.addEventListener('submit', function (e) {
+ const fileRange = (fileForm.querySelector('#file_range') || { value: '' }).value.trim();
+ const category = (fileForm.querySelector('#category') || { value: '' }).value.trim();
+ const value = (fileForm.querySelector('#value') || { value: '' }).value.trim();
+ const checkedOp = fileForm.querySelector('input[name="operation"]:checked');
+ const operation = checkedOp ? checkedOp.value : '';
if (!fileRange) {
alert('Please enter a file ID range');
@@ -43,18 +49,17 @@ document.querySelector('form').addEventListener('submit', function(e) {
return;
}
- // Only require value for add operations
if (operation === 'add' && !value) {
alert('Please enter a tag value when adding tags');
e.preventDefault();
return;
}
- // Basic validation of range format
const rangePattern = /^[\d\s,-]+$/;
if (!rangePattern.test(fileRange)) {
alert('File range should only contain numbers, commas, dashes, and spaces');
e.preventDefault();
return;
}
+});
});
\ No newline at end of file