Skip to content

Restore the Add "Other" button after bulk editing options#2616

Closed
shervElmi wants to merge 1 commit into
masterfrom
restore-add-other-button-after-bulk-edit
Closed

Restore the Add "Other" button after bulk editing options#2616
shervElmi wants to merge 1 commit into
masterfrom
restore-add-other-button-after-bulk-edit

Conversation

@shervElmi
Copy link
Copy Markdown
Contributor

When editing radio button options using Bulk Edit or AI generation, the Add "Other" button would disappear and not come back. This fix restores the Add "Other" button visibility after updating options.

Related Issue

Fixes https://github.com/Strategy11/formidable-pro/issues/6092

Before

CleanShot 2025-11-28 at 21 40 29

After

CleanShot 2025-11-28 at 21 57 06

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 26.18%. Comparing base (e0a38d6) to head (ebd3dcf).
⚠️ Report is 135 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #2616   +/-   ##
=========================================
  Coverage     26.17%   26.18%           
- Complexity     8831     8833    +2     
=========================================
  Files           144      144           
  Lines         29798    29809   +11     
=========================================
+ Hits           7799     7804    +5     
- Misses        21999    22005    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 28, 2025

Walkthrough

The bulk options update flow now retrieves the options container element and determines if an "Other" option exists before updating its HTML. Upon successful modal close, the "Other" button is conditionally revealed if the option is present, using optional chaining for safe element access.

Changes

Cohort / File(s) Summary
Bulk options update logic
js/src/admin/admin.js
Modified options container update to compute "Other" option existence before HTML update; conditionally reveals "Other" button on modal close via optional chaining

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify the conditional logic correctly detects "Other" option presence from DOM content
  • Confirm optional chaining usage (other_button_{fieldId}) safely handles missing elements
  • Check that the two-step update (compute → mutate → reveal) maintains proper state consistency

Suggested reviewers

  • Crabcyborg

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main functional change: restoring the 'Add Other' button after bulk editing options, which directly matches the changeset's objective.
Description check ✅ Passed The description clearly explains the problem (button disappearance), the solution, includes a related issue reference, and provides before/after screenshots demonstrating the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch restore-add-other-button-after-bulk-edit

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
js/src/admin/admin.js (1)

11095-11106: Make “Add Other” button re‑show logic depend on post‑update state as well

Right now hasOtherOption is computed from the DOM before you replace innerHTML, and you use it only to decide whether to re‑show #other_button_{fieldId}. If the returned HTML ever still includes an .frm_other_option, this would still unhide the “Add Other” button and allow users to add a second “Other” option.

You can make this more robust by tracking both previous and current presence of the .frm_other_option after the bulk update:

  • Only re‑show the “Add Other” button when the field previously had an “Other” option and the updated HTML no longer does.
  • Optionally hide the button when the updated HTML does contain an “Other” option, to preserve the “only one Other” invariant.

Here’s a minimal adjustment that stays within the current structure:

-				success: function( html ) {
-					const optionsListEl = document.getElementById( 'frm_field_' + fieldId + '_opts' );
-					const hasOtherOption = optionsListEl.querySelector( '.frm_single_option.frm_other_option' );
-					optionsListEl.innerHTML = html;
+				success: function( html ) {
+					const optionsListEl = document.getElementById( 'frm_field_' + fieldId + '_opts' );
+					const previouslyHadOther = !! optionsListEl?.querySelector( '.frm_single_option.frm_other_option' );
+
+					if ( optionsListEl ) {
+						optionsListEl.innerHTML = html;
+					}
 					wp.hooks.doAction( 'frm_after_bulk_edit_opts', fieldId );
 					resetDisplayedOpts( fieldId );
 
 					if ( typeof modal !== 'undefined' ) {
 						modal.dialog( 'close' );
 						document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' );
-						if ( hasOtherOption ) {
-							document.getElementById( `other_button_${ fieldId }` )?.style.removeProperty( 'display' );
-						}
+						const currentlyHasOther = !! optionsListEl?.querySelector( '.frm_single_option.frm_other_option' );
+						const addOtherButton = document.getElementById( `other_button_${ fieldId }` );
+
+						if ( addOtherButton ) {
+							// Show button only when an "Other" was removed by this bulk update.
+							if ( previouslyHadOther && ! currentlyHasOther ) {
+								addOtherButton.style.removeProperty( 'display' );
+							// Keep button hidden when an "Other" still exists.
+							} else if ( currentlyHasOther ) {
+								addOtherButton.style.display = 'none';
+							}
+						}
 					}
 				}

This keeps the behavior targeted to the “Other removed via bulk update” case and avoids exposing the “Add Other” button while an Other option is still present.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c076266 and ebd3dcf.

📒 Files selected for processing (1)
  • js/src/admin/admin.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
js/src/admin/admin.js (1)
js/admin/dom.js (3)
  • modal (12-109)
  • modal (14-14)
  • modal (607-607)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Cypress
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: Cypress
  • GitHub Check: Cypress
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: PHP 8 tests in WP trunk

@Crabcyborg
Copy link
Copy Markdown
Contributor

Crabcyborg commented Dec 3, 2025

Thanks @shervElmi!

It looks like this was recently introduced with #2534. Truong commented on it, but it looks like it was merged anyway.

Instead Abdi had logged a new issue for it https://github.com/Strategy11/formidable-pro/issues/6077. But it looks like it wasn't an issue until that update. It seems to work as expected in v6.25.1.

I updated it in a commit on Abdi's PR for the option limiting update, but the issue was on master for a while.

It should be fixed with #2620.

I don't believe we need this PR anymore.

@Crabcyborg Crabcyborg closed this Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants