Skip to content

Fix section fields incorrectly merging into the previous row after reload - #2694

Merged
Crabcyborg merged 11 commits into
masterfrom
fix/field-group-section-row-wrap
Aug 25, 2026
Merged

Fix section fields incorrectly merging into the previous row after reload#2694
Crabcyborg merged 11 commits into
masterfrom
fix/field-group-section-row-wrap

Conversation

@shervElmi

@shervElmi shervElmi commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

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

This update fixes an issue in the form builder where adding a section after a partially-sized field could cause the section to appear in the same row after refreshing the page. Now, sections correctly start on a new row when needed, keeping the builder layout consistent before and after reload.

Summary by CodeRabbit

  • Bug Fixes
    • Improved field layout handling in grid-based forms.
    • Fixed row placement when full-width sections follow multi-column fields.
    • Preserved nested section rows and end markers in affected layouts.
    • Corrected wrapper behavior for sections and grouped fields beginning a row.
    • Prevented layout overflow and misplaced field grouping in affected configurations.

…r fields to check section_size before opening section
@shervElmi
shervElmi marked this pull request as ready for review January 5, 2026 18:57
@coderabbitai

coderabbitai Bot commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 710a90aa-588e-4661-8e97-0e976773837e

📥 Commits

Reviewing files that changed from the base of the PR and between bb71b7c and 25bab5a.

📒 Files selected for processing (2)
  • classes/helpers/FrmFieldGridHelper.php
  • tests/phpunit/fields/test_FrmFieldGridHelper.php

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Simplifies field wrapper state handling and corrects closure behavior for nested sections. Updates the section-overflow test to verify that an oversized section starts a new row.

Changes

Field wrapper logic

Layer / File(s) Summary
Wrapper closure rules
classes/helpers/FrmFieldGridHelper.php
Removes private group and section-start flags and their initialization. Updates wrapper closure logic to close a nested section helper only when the section is open.
Oversized section regression coverage
tests/phpunit/fields/test_FrmFieldGridHelper.php
Renames the section-overflow test and updates its expected layout from [1,2[3]4] to [1][2[3]4].

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 25bab

The change is a localized fix to keep sections on the correct row after reload, with no actionable merge-blocking risk remaining beyond normal checks and review.

Suggested reviewers: crabcyborg

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: preventing section fields from merging into the previous row after a form reload.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/field-group-section-row-wrap

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.

@shervElmi

Copy link
Copy Markdown
Contributor Author

Hi @lauramekaj1,

I am adding you as a reviewer for a deep review, and I would appreciate it if you could test complex groups with sections, without sections, and with complex layout columns.

@coderabbitai coderabbitai 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
classes/helpers/FrmFieldGridHelper.php (1)

207-208: Correct initialization of tracking flags.

The flags properly capture the state of the first field when a new wrapper begins.

One minor observation: is_group_start and is_section_start are not reset in close_field_wrapper(), unlike current_list_size and current_field_count. This works because begin_field_wrapper() always sets them before use, but explicit resets would improve symmetry with other state variables.

🔎 Optional: Reset flags in close_field_wrapper for consistency
 private function close_field_wrapper() {
 	$this->maybe_close_section_helper();
 	echo '</ul></li>';
 	$this->parent_li           = false;
 	$this->current_list_size   = 0;
 	$this->current_field_count = 0;
+	$this->is_group_start      = false;
+	$this->is_section_start    = false;
 }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f06fd5 and 390a2f8.

📒 Files selected for processing (1)
  • classes/helpers/FrmFieldGridHelper.php
⏰ 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). (1)
  • GitHub Check: Cypress
🔇 Additional comments (2)
classes/helpers/FrmFieldGridHelper.php (2)

63-79: LGTM!

The new tracking flags are well-documented with clear examples explaining the intended behavior. The PHPDoc comments provide good context for future maintainers.


175-197: Logic flow is correct for the bug fix.

The refactored method properly handles the section wrapping issue:

  1. Short-circuits when there is no parent list item (no wrapper to close).
  2. Adds special handling for divider fields when a section isn't already open.
  3. Lets section_helper take precedence when present.

The condition on line 184 correctly ensures dividers start on a new row when fields aren't explicitly grouped (!is_group_start), which addresses the reported issue.

@coderabbitai coderabbitai 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.

Actionable comments posted: 0

🧹 Nitpick comments (3)
classes/helpers/FrmFieldGridHelper.php (3)

176-184: Core logic looks correct for the stated objective.

The early exit and divider handling properly enforce that sections start new rows unless explicitly grouped. The condition at line 183 ensures dividers only remain in the same row when is_group_start is true (first field had frm_first), which matches the PR's goal of fixing unintended merging after reload.

Consider adding an inline comment above line 182 explaining the three conditions for better maintainability:

// Close the current row before a section if:
// 1. The section would overflow the grid, OR
// 2. The section explicitly starts a new row (frm_first), OR  
// 3. The current row wasn't intentionally started as a group
if ( 'divider' === $this->field->type && ! $this->section_is_open ) {

194-194: Consider adding a comment to clarify the section-start condition.

The extended condition ( $this->is_section_start && ! $this->is_group_start ) ensures fields after a section start a new row unless explicitly grouped. While the logic is sound, an inline comment would improve maintainability.

🔎 Suggested clarification comment
+	// Also close if the row started with a section but wasn't marked as an intentional group
 	return ! $this->can_support_current_layout() || $this->is_frm_first || ( $this->is_section_start && ! $this->is_group_start );

205-206: Flag initialization looks correct.

The flags properly capture the state of the first field in each row. The logic works because flags are overwritten when begin_field_wrapper() is called for a new row.

For defensive coding, consider resetting these flags in close_field_wrapper() (around line 293) to make the lifecycle explicit and prevent potential future issues if the logic changes:

private function close_field_wrapper() {
	$this->maybe_close_section_helper();
	echo '</ul></li>';
	$this->parent_li           = false;
	$this->current_list_size   = 0;
	$this->current_field_count = 0;
	$this->is_group_start      = false;
	$this->is_section_start    = false;
}

This makes the state management more explicit, though the current implementation is functionally correct.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 390a2f8 and 4707c6a.

📒 Files selected for processing (1)
  • classes/helpers/FrmFieldGridHelper.php
⏰ 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). (3)
  • GitHub Check: Cypress
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: PHP 7.4 tests in WP 6.9
🔇 Additional comments (1)
classes/helpers/FrmFieldGridHelper.php (1)

63-79: LGTM! Clear documentation with helpful examples.

The new flags are well-documented with clear intent. The example for is_group_start effectively illustrates the grouping behavior.

@Crabcyborg Crabcyborg added this to the 6.28 milestone Jan 5, 2026
@lauramekaj1

Copy link
Copy Markdown
Contributor

@shervElmi I tested it and it's working as expected. Thank you!

@Crabcyborg Crabcyborg modified the milestones: 6.28, 6.29 Feb 12, 2026
@Crabcyborg Crabcyborg modified the milestones: 6.29, 6.30 Mar 9, 2026
@Crabcyborg Crabcyborg removed this from the 6.32 milestone Jun 16, 2026
@Crabcyborg Crabcyborg added this to the 6.33 milestone Jun 16, 2026
@Crabcyborg Crabcyborg modified the milestones: 6.33, 6.34 Jul 14, 2026
@Crabcyborg Crabcyborg modified the milestones: 6.34, 6.35 Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@deepsource-io

deepsource-io Bot commented Aug 24, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 538d304...25bab5a 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 ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Aug 25, 2026 12:22p.m. Review ↗
JavaScript Aug 25, 2026 12:22p.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.

@Crabcyborg Crabcyborg 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.

I added some unit tests and fix a bug.

I think this is good to merge now.

🚀

@Crabcyborg
Crabcyborg merged commit 8e243b6 into master Aug 25, 2026
21 of 22 checks passed
@Crabcyborg
Crabcyborg deleted the fix/field-group-section-row-wrap branch August 25, 2026 12:40
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.

3 participants