简体   繁体   中英

Plone z3c.form.GroupForm with inline validation

I'm stuck using two schemas to build a z3c.GroupForm that has inline validation:

Following https://pypi.python.org/pypi/z3c.form#group-forms I did:

from plone.directives.dexterity import AddForm
from z3c.form import field
from z3c.form import group, form

class CustomerGroup( group.Group ):
    label = u'Customer'
    fields = field.Fields(ICustomer, prefix='customer')

class CustomerRegistrationAddForm(group.GroupForm, AddForm):
    ignoreContext = True
    fields = field.Fields(IEmailUser).omit('customer')
    groups = (CustomerGroup,)

This works. But it gives me really plain rendering and no inline validation. I tried to include mixings from plone.autoform but these seem not to be compatible -> MRO errors.

I am quite sure that I missed something. There are plone.app.z3cform and other wrappers for z3c.form usage in Plone. But I do not find an example of using them for z3c.groups, so I tried the basic z3c variant.

The usecase I like to achieve is the following: A form that has the fields of Schema A and Schema B each in a tab, respectively. The form action handling then is manually coded and will take care of the handling of underlying content types. With other words: no dexterity "positive connotation" magic will/should be used.

But I like to have inline validation according to the schema hints and adapters I registered for the schemas.

Problem solved. The groups of Z3c are called fieldsets in Plone, now. The following does the trick.

from plone.autoform.form import AutoExtensibleForm
from plone.supermodel import model
from z3c.form import form
from plone.autoform import directives

class ICustomerRegistration( IEmailUser, ICustomer ):
    model.fieldset('EmailUser',
        label=_(u"EMail User"),
        fields=['email', 'firstname', 'lastname', ]
        )

    model.fieldset('Customer',
        label=_(u"Customer"),
        fields=['enterprise',
                'street',
                'house_number',
                'postal_code',
                'city',
                ]
        )

class CustomerRegistrationAddForm(AutoExtensibleForm, form.Form):
    ignoreContext = True
    schema = ICustomerRegistration

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM