Skip to content

Commit 0cbc715

Browse files
matteiusclaude
andcommitted
fix: simplify ApprovalStepForm layout to current-stage fields only
_setup_layout was including ALL form fields (other stages + submission data) in the crispy layout, causing empty section headers, KeyError warnings for unregistered fields, and a nested <form> tag. Since the template already renders submission data via _form_data_rows.html, the crispy form only needs the current stage's fields. Set form_tag=False to avoid the nested form. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f7cf5b3 commit 0cbc715

2 files changed

Lines changed: 10 additions & 34 deletions

File tree

django_forms_workflows/forms.py

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,41 +1845,17 @@ def _build_layout_fields(self, field_defs):
18451845
def _setup_layout(self):
18461846
"""Setup Crispy Forms layout."""
18471847
self.helper = FormHelper()
1848-
self.helper.form_method = "post"
1849-
self.helper.form_class = "needs-validation"
1848+
self.helper.form_tag = False
18501849

1851-
layout_fields = []
1850+
# Only layout fields for the current approval stage. Submission
1851+
# data is rendered separately by the template (via _form_data_rows).
18521852
stage_id = self.approval_task.workflow_stage_id
1853-
1854-
# Separate fields into current stage vs other (read-only) groups
1855-
current_stage_defs = []
1856-
other_defs = []
1857-
for field_def in self.form_definition.fields.order_by("order"):
1858-
if field_def.workflow_stage_id == stage_id:
1859-
current_stage_defs.append(field_def)
1860-
else:
1861-
other_defs.append(field_def)
1862-
1863-
# Add submitted data section first (read-only)
1864-
if other_defs:
1865-
layout_fields.append(
1866-
HTML('<h3 class="mb-3">Submitted Information (Read-Only)</h3>')
1867-
)
1868-
layout_fields.extend(self._build_layout_fields(other_defs))
1869-
1870-
# Add current stage fields section with width support
1871-
current_stage_fields = self._build_layout_fields(current_stage_defs)
1872-
if current_stage_fields:
1873-
layout_fields.append(HTML('<hr class="my-4">'))
1874-
step_name = self.approval_task.step_name or "Review"
1875-
layout_fields.append(
1876-
HTML(f'<h3 class="mb-3">{step_name} - Your Input</h3>')
1877-
)
1878-
layout_fields.extend(current_stage_fields)
1879-
1880-
self.helper.layout = Layout(*layout_fields)
1881-
self.helper.form_id = f"approval_form_{self.submission.pk}"
1882-
self.helper.attrs = {"novalidate": True}
1853+
current_stage_defs = [
1854+
f
1855+
for f in self.form_definition.fields.order_by("order")
1856+
if f.workflow_stage_id == stage_id
1857+
]
1858+
self.helper.layout = Layout(*self._build_layout_fields(current_stage_defs))
18831859

18841860
def get_updated_form_data(self):
18851861
"""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-forms-workflows"
3-
version = "0.64.1"
3+
version = "0.64.2"
44
description = "Enterprise-grade, database-driven form builder with approval workflows and external data integration"
55
license = "LGPL-3.0-only"
66
readme = "README.md"

0 commit comments

Comments
 (0)