Skip to content

Refresh source fields for Lookup and Dynamic choice sorting - #3608

Draft
Crabcyborg wants to merge 9 commits into
masterfrom
feat/lookup-dynamic-sort
Draft

Crabcyborg wants to merge 9 commits into
masterfrom
feat/lookup-dynamic-sort

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Refresh the Order by field dropdown when a Lookup or Dynamic field changes its source form. Keep the available source fields in sync with the selected form.

Companion PR: https://github.com/Strategy11/formidable-pro/pull/6885

Testing

Verified with companion Pro source ordering suite: 5 tests, 12 assertions passed. Rebuilt the production admin JavaScript bundle.

ESLint, Oxlint, spelling, and production bundle build passed.

Browser verification has not been repeated for this split. Manual review: Set a Lookup or Dynamic field to order by another source field. Check ascending and descending ordering, blank sort values, and changing the source form.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@deepsource-io

deepsource-io Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in d27ebf9...df9f8a8 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Dec 1, 2026 7:33p.m. Review ↗
JavaScript Dec 1, 2026 7:33p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Oct 22, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving: the builder JS does what it says, with three small non-blocking notes below.

What I ran (preview env, Lite on this PR + Pro companion #6885, a Lookup and a Dynamic field on seeded forms):

  • Lookup: changing the source form from SrcA to SrcB replaced Order by with SrcB's fields and reset it to "Option label". Setting the form to blank cleared it down to "Option label".
  • Dynamic: changing the source form replaced Order by with the new form's fields. Switching the source to Taxonomy cleared it.
  • The initial server-rendered Order by list matched the source field list on both field types.
  • Not tested: the actual front-end sort order (that is the Pro half), and I did not rebuild formidable_admin.js to confirm it matches the source. Psalm is red, but it fails the same way on master and this diff has no PHP.

Non-blocking notes (nothing posted inline, all in js/src/admin/admin.js):

  1. getTaxOrFieldSelection success callback: $selectedFields.get( 0 ).querySelector( 'select' ) throws if the container is gone when the response lands. The old .html().show() was a no-op on an empty set. Use const container = $selectedFields.get( 0 ); const sourceSelect = container ? container.querySelector( 'select' ) : null;.
  2. toggleFormTax, val === 'form' branch: it empties the source field select but does not reset Order by, so the old form's fields stay listed. Add updateOrderFieldSelection( id, [] ); next to empty( $showFields );.
  3. After a form change, Order by is copied from the source select, which frm_get_options_for_get_values_field truncates to 30 characters. The initial server render in order.php does not truncate. Long field names read differently before and after a change. Cosmetic.

This PR is still a draft and depends on formidable-pro#6885 for the frm_order_field_<id> element. Without it updateOrderFieldSelection returns early, which is safe.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Oct 22, 2026
@Crabcyborg Crabcyborg added run e2e tests Run the Cypress end-to-end suite on this PR and removed run e2e tests Run the Cypress end-to-end suite on this PR labels Nov 30, 2026
Crabcyborg and others added 5 commits December 1, 2026 09:33
…-sort

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Skip the source select lookup when the field selection container is
gone before the AJAX response lands. Clear the Order by options when a
Dynamic field switches its source back to a form. Rebuild the builder
bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Crabcyborg

Copy link
Copy Markdown
Contributor Author

Addressed franky's review notes in df9f8a8:

  1. getTaxOrFieldSelection null container: fixed in df9f8a8. The success callback now reads $selectedFields.get( 0 ) into container and only calls querySelector when it exists.
  2. toggleFormTax form branch: fixed in df9f8a8. It now calls builder.conditionalLogic.updateOrderFieldSelection( id, [] ) next to empty( $showFields ), so the old form's fields no longer stay in Order by.
  3. Truncated Order by labels: not changed in Lite. Lite copies whatever the source select holds and cannot recover the full name. The 30 character truncation comes from Pro's show_options_for_get_values_field(), and the untruncated initial render is Pro's order.php, so the consistent fix belongs in https://github.com/Strategy11/formidable-pro/pull/6885 (for example FrmAppHelper::truncate( $order_option->name, 30 ) in order.php).

Also merged the latest master (clean) and rebuilt js/formidable_builder.js. ESLint and Oxlint pass on the changed file.

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.96%. Comparing base (c946c44) to head (df9f8a8).
⚠️ Report is 45 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3608      +/-   ##
============================================
+ Coverage     48.87%   48.96%   +0.09%     
- Complexity    14432    14465      +33     
============================================
  Files           240      241       +1     
  Lines         48416    48481      +65     
============================================
+ Hits          23664    23740      +76     
+ Misses        24752    24741      -11     

☔ View full report in Codecov by Harness.
📢 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.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Dec 1, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve. The two code notes from my last review are fixed at this head, and the third is correctly left to the Pro PR.

Checked at df9f8a8 (preview env, Lite on this PR plus Pro #6885 at 49a1dbd, seeded forms SrcA / SrcB and a Target form with one Lookup and one Dynamic field, jQuery ajax and DOM state read from the open builder):

  • Lookup: source form SrcA to SrcB replaced Order by with Beta one / Beta two / Beta three and reset it to "Option label". Source set to blank cleared it down to "Option label".
  • Dynamic: source form SrcA to SrcB replaced Order by with the SrcB fields.
  • Fix 1 (null container): I changed the source form and removed #frm_show_selected_fields_12 before the response landed. No error was thrown (no error or unhandledrejection events), and Order by reset to "Option label".
  • Fix 2 (toggleFormTax form branch): I added a fake stale option to Order by, then switched the Dynamic source type to Form Entries. The stale option was removed.
  • The committed js/formidable_builder.js bundle contains updateOrderFieldSelection and the frm_order_field_ lookup. A fresh webpack build here gives different module ids in every bundle, so I could not byte-compare it and compared the content instead.
  • Diff re-read in full (3 files, conditionalLogic.js, fieldPreview.js, the bundle): updateOrderFieldSelection returns early when the frm_order_field_<id> element is missing, so Lite alone is still safe.

Not an issue for this PR: truncated Order by labels after a form change come from Pro's show_options_for_get_values_field() (30 characters) versus the untruncated order.php. Agreed that the fix belongs in formidable-pro#6885.

Not exercised: the front-end sort order itself (the Pro half). The PR adds no JS unit tests, and CI skipped the JS unit tests job, so nothing automated covers updateOrderFieldSelection. I did not run node --test for it because no test targets it. Skills not run (manual read of the diff). Psalm and PHPUnit are green and this diff has no PHP.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Dec 1, 2026
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.

1 participant