Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/FormManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,21 @@ private function prepare(): void
}

$i = 0;
$isPageBreakLastFormField = false;

foreach ($this->formFieldModels as $k => $formField) {
$this->formFieldsPerStep[$i][$k] = $formField;

if ($this->isPageBreak($formField)) {
$isPageBreakLastFormField = true;

// Set the name on the model, otherwise one has to enter it in the back end every time
$formField->name = $formField->type;

// Increase counter
++$i;
} else {
$isPageBreakLastFormField = false;
}

// If we have a regular submit form field, that's a misconfiguration
Expand All @@ -432,6 +437,20 @@ private function prepare(): void
}
}

// If the last form field is not a page break, we need to merge the last step into the previous one
if (!$isPageBreakLastFormField) {
$lastStepIndex = count($this->formFieldsPerStep) - 1;
Comment thread
qzminski marked this conversation as resolved.

if (isset($this->formFieldsPerStep[$lastStepIndex], $this->formFieldsPerStep[$lastStepIndex - 1])) {
$this->formFieldsPerStep[$lastStepIndex - 1] = [
...$this->formFieldsPerStep[$lastStepIndex - 1], // Second last step
...$this->formFieldsPerStep[$lastStepIndex], // Last step
];

array_pop($this->formFieldsPerStep);
}
}

$this->prepared = true;
$this->preparing = false;
}
Expand Down