Skip to content

Commit

Permalink
Nested forms respect if the parent form is non-editable (fixes #467)
Browse files Browse the repository at this point in the history
  • Loading branch information
boxed committed Apr 15, 2024
1 parent b30870b commit 949e17e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions iommi/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,8 @@ def on_bind(self) -> None:

self._evaluate_parameters['instance'] = self.instance
self.editable = evaluate_strict(self.editable, **self.iommi_evaluate_parameters())
if self.parent_form is not None and self.parent_form.editable is False:
self.editable = False

self.title = evaluate_strict(self.title, **self.iommi_evaluate_parameters())
build_and_bind_h_tag(self)
Expand Down
16 changes: 16 additions & 0 deletions iommi/form__tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3810,3 +3810,19 @@ def test_duration_render_value():
assert duration_render_value(timedelta(seconds=2.1)) == '2.10s'
assert duration_render_value(timedelta(minutes=3, seconds=2.1)) == '3m 2.10s'
assert duration_render_value(timedelta(hours=7, minutes=3, seconds=2.1)) == '7h 3m 2.10s'


def test_nested_form_respects_parents_editable_false():
class ChildForm(Form):
name = Field.text()

class ParentForm(Form):
class Meta:
editable = False

child_name = ChildForm()

pf = ParentForm().bind()
assert not pf.editable

assert not pf.nested_forms.child_name.editable

0 comments on commit 949e17e

Please sign in to comment.