iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
688 stars 47 forks source link

Nested form doesn't respect parent form's `editable` attribute #467

Closed yurkobb closed 4 months ago

yurkobb commented 11 months ago
class ChildForm(Form):
    name = Field.text()

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

    child_name = ChildForm()

pf.editable
# returns: False

pf.nested_forms.child_name.editable
# returns: True

As a workaround one can do:

class ChildForm(Form):
    class Meta:
        def read_nested_form_from_instance(form, instance, **kwargs):
            form.editable = form.parent_form.editable
            return Form.read_nested_form_from_instance(form, instance, **kwargs)