Ticket #10022 (closed Bug: fixed)

Opened 4 years ago

Last modified 4 years ago

plone.z3cform.layout.FormWrapper contents method doesn't work anymore

Reported by: petschki Owned by: nouri
Priority: major Milestone: 3.3.5
Component: General Version:
Keywords: z3cform layout Cc:

Description

i have a z3cform in a viewlet and used the FormWrapper class something like this:

from plone.app.layout.viewlets import ViewletBase
from plone.z3cform import layout

class CouponCodeFormViewlet(ViewletBase, layout.FormWrapper):
    """
    """
    index = ViewPageTemplateFile('couponcode_viewlet.pt')
    form = CouponCodeForm # subclass of z3c.form.form.Form

until version 0.5.7 of plone.z3cform i get the form when i call "view/contents" in the viewlet template. since of version 0.5.8 this doesn't work anymore. i think it's because the z2.switch_on has been moved to the update() function ant this is not called anywhere?

Change History

comment:1 Changed 4 years ago by vincentfretin

  • Status changed from new to closed
  • Resolution set to fixed

FormWrapper have now update and render methods so the update phase and render phase is well separated. In your case ViewletBase overwrites FormWrapper update and render methods.

You can adapt your code to something like that:

from plone.app.layout.viewlets import ViewletBase
from plone.z3cform import layout

class CouponCodeFormViewlet(ViewletBase, layout.FormWrapper):
    """
    """
    index = ViewPageTemplateFile('couponcode_viewlet.pt')
    form = CouponCodeForm # subclass of z3c.form.form.Form
    def update(self):
        ViewletBase.update(self)
        layout.FormWrapper.update(self)

But really if I were you, I'll do something like this:

from Acquisition import aq_inner
from plone.app.layout.viewlets import ViewletBase
from plone.z3cform import layout
from z3c.form.interfaces import IFormLayer

class CouponCodeFormViewlet(ViewletBase):
    """
    """
    index = ViewPageTemplateFile('couponcode_viewlet.pt')
    def update(self):
        super(CouponCodeFormViewlet, self).update()
        z2.switch_on(self, request_layer=IFormLayer)
        self.form = CouponCodeForm(aq_inner(self.context), self.request))
        self.form.update()

and in your template, you call view/form/render

comment:2 Changed 22 months ago by davisagli

  • Component changed from Infrastructure to General
Note: See TracTickets for help on using tickets.