Repository navigation
Improve form builder navigation and field context - #3668
Crabcyborg wants to merge 5 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| PHP | Nov 4, 2026 2:35p.m. | Review ↗ | |
| JavaScript | Nov 4, 2026 2:35p.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.
# Conflicts: # css/frm_admin.css # js/formidable_admin.js # js/src/admin/admin.js
Sections in the builder become bordered cards with a tinted header, a field count and a real collapse button that remembers its state per form in browser storage. The collapse control now works for sections nested inside tabs and accordions, where the old link did nothing. The count skips sections, tab and accordion containers and their end markers, so a tabs field reports the fields inside its panels. The ID and move/menu icons stay hover-only and overlay the header, so narrow layout columns keep a readable title. Selecting a field outlines the cards it sits in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Section cards, the collapse button, the field count and the remembered collapsed state now come from builderSections.js, split out for review on its own. builderContext.js uses its setCollapsed helper for Collapse all, Expand all and the breadcrumb, and the duplicate section rules are removed from _context.scss. The display menu moves from the top bar to a bar above the canvas. In the top bar it narrowed the form navigation enough for the Workflows add-on to hide its tab. The drag destination text is now announced to screen readers only, since the visible banner covered the top of the canvas. The dashed outline still marks the target. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Request changes: one real bug in the conditional badge text, and the new badge logic has no tests. The rest checked out live.
Tests run: node --test tests/js/*.test.mjs at a557e19 (the repo's JS unit job was skipped on this draft, so I ran it): 93 pass, 0 fail. builderSections.test.mjs covers only the field-count helpers.
Checked live (preview env, Lite at this head plus Pro, committed bundles, a seeded form with a section, conditional/calculated/hidden/restricted fields and a page break):
- Section card shows "4 fields" and a working collapse button; Conditional, Calculated, Hidden and Restricted visibility badges all render with the right text.
- Display menu: Collapse all collapsed the section and both pages and left the Submit row visible; the choice is stored in
localStorage(["164"]) and the section is still collapsed after a reload; Expand all restores. - Selecting "Company note" gives the breadcrumb
Registration details › Company notewitharia-current="location"on the last crumb, and the section card gets the selected outline. - A 211-field form: the badge pass waits for lazily rendered fields (7 badged at first load, 95 after scrolling them in).
Findings
- Blocking: conditional badge text uses the wrong condition when a rule row has no field (inline,
builderContext.js). Screenshot in the inline comment. - Blocking: no tests for
getBadges(inline). - Non-blocking: the manifest is built inline in the view template and its option-key list is duplicated in PHP and JS (inline,
form.php).
Not exercised: nested sections, Tabs/Accordion containers, the drag-destination outline and screen reader text (jQuery UI drag is not scriptable here), keyboard operation, a Lite-only builder, and the published form. I did not rebuild the bundles from source; I ran the committed formidable_admin.js / frm_admin.css, which contain the new code. A stacked PR on #3762: that PR needs to merge first.
| function getBadges( field, options, context ) { | ||
| const badges = []; | ||
| const enabled = ! [ '0', 0, false ].includes( options.enable_conditional_logic ); | ||
| const rules = enabled ? Object.values( options.hide_field || {} ).filter( Boolean ) : []; |
There was a problem hiding this comment.
Bug: the badge reads the wrong condition when a rule row has no field selected.
rules drops blank hide_field entries, then index is used to look up hide_field_cond / hide_opt, which still include the blank row. Every row after a blank one gets the wrong operator and value.
Repro on this branch (builder, field with two condition rows: row 1 field left on "Select field", row 2 = Field 0-1 is not y). Badge text after the change:
Shown when Field 0-1 is
Expected: Shown when Field 0-1 is not y.
Note: I produced the second row by cloning the first row's controls in the DOM, then setting the values and firing change; the badge logic reads exactly those controls.
The same filtered rules array is used for isGrouped (the rules.some( ( id, index ) => ... check), so keep the original index there too. Fix: keep each rule's original index and filter after:
const rules = enabled
? Object.values( options.hide_field || {} ).map( ( id, index ) => ( { id, index } ) ).filter( ( { id } ) => id )
: [];and use rule.id / rule.index in the isGrouped check and in the conditions map (options.hide_field_cond?.[ index ], options.hide_opt?.[ index ]).
| * @param {Object} context Names and options indexed by field ID. | ||
| * @return {Array} Labels and descriptions. | ||
| */ | ||
| function getBadges( field, options, context ) { |
There was a problem hiding this comment.
No tests cover this function, and it holds the most logic in the PR: conditional vs grouped detection, operator wording, the calc formula rewrite, and the hidden/restricted branches. The one new test file only covers the section field-count helpers. Finding 1 above is exactly the kind of bug a test here would have caught.
Fix: export getBadges and add tests/js/builderContext.test.mjs (same style as builderSections.test.mjs; wp.hooks.applyFilters needs a stub on globalThis.wp). Cases to cover at minimum:
- a simple show rule and a hide rule, with
anyandall - a blank-field row followed by a real row (the bug above)
- the grouped fallback text (
has_rules,hide_group, non-numeric field id) - a calc formula with
[12]replaced by the field name - hidden field type, and
admin_onlyas'','everyone','0'and a role array - conditional logic disabled (
enable_conditional_logic: '0') gives no Conditional badge
| 'name' => wp_strip_all_tags( $context_field->name ), | ||
| 'options' => array_intersect_key( | ||
| (array) $context_field->field_options, | ||
| array_flip( array( 'hide_field', 'hide_field_cond', 'hide_opt', 'hide_group', 'hide_compare_field', 'hide_compare_measure', 'enable_conditional_logic', 'show_hide', 'any_all', 'calc', 'calc_type', 'admin_only' ) ) |
There was a problem hiding this comment.
Non-blocking: this list is duplicated in OPTION_KEYS (js/src/admin/builderContext.js), and the manifest is built inline in a view template.
Two copies of the same 12 keys have to stay in sync by hand; add a key in one place and the badge silently ignores it in the other. The loop that shapes the data also belongs in a helper or controller method rather than the view, which is where the rest of the builder's data prep lives.
Suggested shape: build the array in a helper (for example FrmFormsHelper::get_builder_context( $values['fields'] )) that owns the key list, include the list in the JSON ({ "keys": [...], "fields": {...} }), and have builderContext.js read the keys from it instead of the constant.



Stacked on #3762, which should merge first. That PR carries the section cards, the collapse button, the field count and the remembered collapsed state on their own so they can ship in 7.2. This branch merges it and builds the rest on top.
Changes in this update
builderSections.js(from Show builder sections as collapsible cards #3762).builderContext.jsno longer prepares sections itself. It receives that module'ssetCollapsedhelper and uses it for Collapse all, Expand all and the breadcrumb, which expands collapsed parents. The duplicate section rules are removed from_context.scss.Browser check after this update (Playwright, Lite with Pro and formidable-tabs-accordions): Workflows stays visible in the nav, Collapse all and Expand all collapse and expand every section and store the state, the breadcrumb reads Registration details › Attendee › Company for a field inside a tab, and dragging a field over a nested section outlines it and announces it with no visible banner. No JavaScript errors.
Improve orientation and navigation while editing complex forms. Add section field counts, a selected-field breadcrumb, and readable badges for conditional logic, calculations, hidden fields, and restricted visibility.
Add builder display options to collapse or expand all sections and pages, toggle field details, and remember section collapse preferences per form. Highlight the destination section while dragging fields and keep the submit row visible when pages are collapsed. Include updated production CSS and JavaScript bundles.
Validation
formidable_admin.jsandfrm_admin.csspassed. Webpack reports bundle size warnings for the admin JavaScript.admin.jsfile and no findings in the new builder context module. Oxlint passed without warnings or errors.Manual test plan
🤖 Generated with Claude Code