Skip to content

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

Open
shervElmi wants to merge 8 commits intomasterfrom
fix/field-group-section-row-wrap
Open

Fix section fields incorrectly merging into the previous row after reload#2694
shervElmi wants to merge 8 commits intomasterfrom
fix/field-group-section-row-wrap

Conversation

@shervElmi
Copy link
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.

…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
Copy link
Contributor

coderabbitai bot commented Jan 5, 2026

Walkthrough

Adds two internal flags, is_group_start and is_section_start, and updates wrapper lifecycle logic: begin_field_wrapper() initializes these flags; should_first_close_the_active_field_wrapper() gains an early exit for missing parent, divider-specific handling when no section exists, preserves section-helper precedence, and extends closing conditions to consider the new flags.

Changes

Cohort / File(s) Summary
Field wrapper logic
classes/helpers/FrmFieldGridHelper.php
Added private flags is_group_start and is_section_start set in begin_field_wrapper(). Updated should_first_close_the_active_field_wrapper() to early-exit when parent list item is absent, handle divider fields when no section is open (considering grid overflow, first-field, and group-start), keep existing section_helper precedence, and extend final close condition to include is_section_start and is_group_start checks alongside layout/frm_first.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • lauramekaj1
  • Crabcyborg

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: preventing sections from incorrectly merging into the previous row after page reload, which is the core issue addressed in the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the bug fix for section field layout issues after reload and the expected behavior.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

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.

@shervElmi
Copy link
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.

Copy link
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)
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.

Copy link
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 (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
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
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