Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 926
Dr. Volker Jaenisch Avatar asked Apr 11 '26 10:04

Dr. Volker Jaenisch


1 Answers

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
like image 115
Dr. Volker Jaenisch Avatar answered Apr 13 '26 14:04

Dr. Volker Jaenisch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!