Skip to content

Select forms in administration panel buttons don't work#632

Merged
yingbull merged 4 commits into
develop/dogfishfrom
505-select-forms-buttons-dont-work
Sep 24, 2025
Merged

Select forms in administration panel buttons don't work#632
yingbull merged 4 commits into
develop/dogfishfrom
505-select-forms-buttons-dont-work

Conversation

@LiamStanziani

@LiamStanziani LiamStanziani commented Sep 24, 2025

Copy link
Copy Markdown
Collaborator

Options to Add/Delete/Move Up/Move Down don't work at all, this was fixed in this PR and I also went and fixed a form reset issue where selected options would reset and not have the correct selections when using any of the buttons. Now it is the same as production

Summary by Sourcery

Fix non-functional select form buttons in the administration panel and retain chosen options across Add/Delete/Move actions

Bug Fixes:

  • Re-enable Add/Delete/Move Up/Move Down buttons in the form selection interface and prevent selection reset on action

Enhancements:

  • Persist selected options across form submissions by adding hidden inputs, JSTL fn:contains checks, and corresponding JavaScript to save and restore selections

@sourcery-ai

sourcery-ai Bot commented Sep 24, 2025

Copy link
Copy Markdown

Reviewer's Guide

Restore form selection button functionality and preserve user selections across submissions by refining the JSP form structure, leveraging JSTL functions for option state, and enhancing JavaScript to save and restore selections.

File-Level Changes

Change Details Files
Refine form element attributes and track selection state
  • Changed form 'styleId' attribute to standard 'id' and added 'name' attribute
  • Introduced hidden inputs (savedAddSelection, savedDeleteSelection) to store current selections
src/main/webapp/form/formselect.jsp
Use JSTL functions to retain selected options
  • Imported JSTL functions taglib
  • Updated tags to conditionally add 'selected' based on saved parameters using fn:contains
src/main/webapp/form/formselect.jsp
Add JavaScript logic to save and restore user selections
  • On page load, read hidden fields and repopulate select elements
  • Before form submission, capture current select values into hidden fields in the click handler
src/main/webapp/form/formselect.jsp

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

github-actions Bot commented Sep 24, 2025

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 166983a.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@LiamStanziani LiamStanziani marked this pull request as ready for review September 24, 2025 14:17

@sourcery-ai sourcery-ai 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.

Hey there - I've reviewed your changes - here's some feedback:

  • Using fn:contains on a comma-delimited string for matching selections is brittle and may yield false positives; consider splitting the saved selections into a list or using multiple hidden inputs for exact matches.
  • Extract the inline JavaScript for saving/restoring selections into a separate JS file or utility function to improve maintainability and keep the JSP cleaner.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using fn:contains on a comma-delimited string for matching selections is brittle and may yield false positives; consider splitting the saved selections into a list or using multiple hidden inputs for exact matches.
- Extract the inline JavaScript for saving/restoring selections into a separate JS file or utility function to improve maintainability and keep the JSP cleaner.

## Individual Comments

### Comment 1
<location> `src/main/webapp/form/formselect.jsp:65` </location>
<code_context>
                                                          size="10" style="width:150">
                                             <c:forEach var="f" items="${formHiddenVector}">
-                                                <option value="${f.formName}">
+                                                <option value="${f.formName}" <c:if test="${fn:contains(param.savedAddSelection, f.formName)}">selected</c:if>>
                                                         ${f.formName}
                                                 </option>
</code_context>

<issue_to_address>
**issue (bug_risk):** Using 'fn:contains' for selection may cause issues if form names are substrings of each other.

This can lead to incorrect selection when form names overlap. Use exact matching or a delimiter to avoid this issue.
</issue_to_address>

### Comment 2
<location> `src/main/webapp/form/formselect.jsp:90` </location>
<code_context>
                                                          name="selectedDeleteTypes" size="10" style="width:150">
                                             <c:forEach var="f" items="${formShownVector}">
-                                                <option value="${f.formName}">
+                                                <option value="${f.formName}" <c:if test="${fn:contains(param.savedDeleteSelection, f.formName)}">selected</c:if>>
                                                         ${f.formName}
                                                 </option>
</code_context>

<issue_to_address>
**issue (bug_risk):** Same substring matching issue applies to delete selection options.

Consider updating the matching logic for 'savedDeleteSelection' to prevent unintended selection of multiple options.
</issue_to_address>

### Comment 3
<location> `src/main/webapp/form/formselect.jsp:124-131` </location>
<code_context>
         registerFormSubmit('selectForm', 'dynamic-content');

         $(document).ready(function () {
+            // Restore selections on page load
+            var savedAdd = $("#savedAddSelection").val();
+            var savedDelete = $("#savedDeleteSelection").val();
+            
+            if (savedAdd) {
+                $("select[name='selectedAddTypes']").val(savedAdd);
+            }
+            if (savedDelete) {
+                $("select[name='selectedDeleteTypes']").val(savedDelete);
+            }
</code_context>

<issue_to_address>
**issue (bug_risk):** Restoring selections with .val() may not work as expected for multiple selects if values are comma-separated strings.

If 'savedAdd' or 'savedDelete' are comma-separated, convert them to arrays before using .val() to ensure correct selection restoration.
</issue_to_address>

### Comment 4
<location> `src/main/webapp/form/formselect.jsp:136-138` </location>
<code_context>
             $(".function").click(function () {
-                $("#forward").val($(this).attr("id"));
-
+                // Save current selections to hidden fields
+                $("#savedAddSelection").val($("select[name='selectedAddTypes']").val() || '');
+                $("#savedDeleteSelection").val($("select[name='selectedDeleteTypes']").val() || '');

+                $("#forward").val($(this).attr("id"));
</code_context>

<issue_to_address>
**issue:** Saving selections as strings may not handle multiple selections correctly.

When multiple options are selected, .val() returns an array. Serialize the array before saving, and update the restoration logic to handle this format.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/main/webapp/form/formselect.jsp Outdated
Comment thread src/main/webapp/form/formselect.jsp Outdated
Comment thread src/main/webapp/form/formselect.jsp
Comment thread src/main/webapp/form/formselect.jsp Outdated
@yingbull yingbull merged commit bc02240 into develop/dogfish Sep 24, 2025
13 of 15 checks passed
@yingbull yingbull deleted the 505-select-forms-buttons-dont-work branch January 8, 2026 18:56
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.

Options to Add/Delete/Move Up/Move Down don't work in Administration - Forms/eForms - Select Forms

2 participants