Skip to content

fix: use requestSubmit() to preserve HTML5 form validation#135

Merged
apaegs merged 3 commits into
mainfrom
fix/form-request-submit
Apr 27, 2026
Merged

fix: use requestSubmit() to preserve HTML5 form validation#135
apaegs merged 3 commits into
mainfrom
fix/form-request-submit

Conversation

@viktorlindell12

@viktorlindell12 viktorlindell12 commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved form submission handling in the file upload process for enhanced reliability when no files are selected or when uploads complete.

@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@viktorlindell12 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 33 minutes and 41 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7c4b1507-4d81-49c9-afc6-6bf154c87fae

📥 Commits

Reviewing files that changed from the base of the PR and between 00d219d and 9aed042.

📒 Files selected for processing (1)
  • src/main/resources/static/js/script.js
📝 Walkthrough

Walkthrough

The uploadNewFile() function in the JavaScript code has been modified to use requestSubmit() instead of direct form submission calls at two control-flow exit points: when no files are selected and when uploads complete.

Changes

Cohort / File(s) Summary
Form Submission Enhancement
src/main/resources/static/js/script.js
Modified uploadNewFile() function to replace direct form submission with requestSubmit() method at two exit points for consistent submission handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • apaegs

Poem

🐰 A form once submitted with a trembling call,
Now requests its moment with grace through it all,
Two exits now kindly use requestSubmit() bright,
Replacing the old way—a cleaner delight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: use requestSubmit() to preserve HTML5 form validation' directly and accurately describes the main change: replacing direct form submission calls with requestSubmit() to preserve form validation behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/form-request-submit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/resources/static/js/script.js (1)

64-79: ⚠️ Potential issue | 🟠 Major

Form is submitted even after upload failures.

In the failure (else) and catch branches (lines 64-74) the loop only resets the button state and continues; control still reaches line 79 and the ticket form is submitted. The result: a ticket can be created where some attachments silently never made it into #hidden-file-inputs, while status.innerText is overwritten by "All uploads completed." at line 78, masking the earlier error.

Consider tracking failure and either aborting the final requestSubmit() or prompting the user before submitting:

♻️ Suggested change
+    let hadFailure = false;
     for (let i = 0; i < filesToUpload.length; i++) {
         ...
             } else {
                 status.innerText = `Failed to upload ${file.name}. Status: ${putRes.status}`;
                 submitBtn.disabled = false;
                 submitBtn.innerText = "Create Ticket";
+                hadFailure = true;
             }
         } catch (error) {
             console.error(error);
             status.innerText = `Error uploading ${file.name}: ${error.message}`;
             submitBtn.disabled = false;
             submitBtn.innerText = "Create Ticket";
+            hadFailure = true;
         }
     }
+    if (hadFailure) {
+        status.innerText = "Some files failed to upload. Please retry before creating the ticket.";
+        return;
+    }
     submitBtn.disabled = false;
     submitBtn.innerText = "Create Ticket";
     status.innerText = "All uploads completed.";
     document.querySelector('form').requestSubmit();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/static/js/script.js` around lines 64 - 79, The form is
always submitted after the upload loop even when individual uploads failed; add
a failure-tracking boolean (e.g., uploadFailed) inside the upload loop and set
it to true in the else and catch branches where putRes.status is non-OK or an
exception occurs (references: submitBtn, status, requestSubmit). After the loop,
check uploadFailed and if true, do not call
document.querySelector('form').requestSubmit(); instead restore
submitBtn.disabled and submitBtn.innerText, update status with a persistent
error message, and optionally prompt the user to retry or confirm before
submitting. Ensure any early-return logic or user prompt is clearly tied to
uploadFailed so successful runs still call requestSubmit().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/resources/static/js/script.js`:
- Line 31: The code calls document.querySelector('form') (used in
uploadNewFile()) which can be null on upload.html and the upload loop error
handlers reset the button but do not stop the process; fix by resolving the form
from the button that triggered the action (use the triggering element's .form
property instead of document.querySelector('form')) and, inside the upload
loop/error handlers (the upload request success/error branches in
uploadNewFile), return or break immediately on any upload failure so the
function does not continue to submit the form at line 79 with missing
attachments and gives clear failure state to the user.

---

Outside diff comments:
In `@src/main/resources/static/js/script.js`:
- Around line 64-79: The form is always submitted after the upload loop even
when individual uploads failed; add a failure-tracking boolean (e.g.,
uploadFailed) inside the upload loop and set it to true in the else and catch
branches where putRes.status is non-OK or an exception occurs (references:
submitBtn, status, requestSubmit). After the loop, check uploadFailed and if
true, do not call document.querySelector('form').requestSubmit(); instead
restore submitBtn.disabled and submitBtn.innerText, update status with a
persistent error message, and optionally prompt the user to retry or confirm
before submitting. Ensure any early-return logic or user prompt is clearly tied
to uploadFailed so successful runs still call requestSubmit().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 99007d34-b573-48a4-ac41-9cb4efc84cb9

📥 Commits

Reviewing files that changed from the base of the PR and between 7f58682 and 00d219d.

📒 Files selected for processing (1)
  • src/main/resources/static/js/script.js

Comment thread src/main/resources/static/js/script.js Outdated
@apaegs
apaegs merged commit 1c30f2f into main Apr 27, 2026
2 checks passed
@apaegs
apaegs deleted the fix/form-request-submit branch April 27, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants