Copy/clone Form Fields (z3c.form)

Hi,
is it possible, or wise to clone/copy Form Fields?

I build a long form for companies, because they have to register for a conference.
We have several contacts (Contact for company, contact for applications,...) in this form.

Can I clone (or better reuse) an Interface (ex IPerson) but rename the fields for for saving?

For example:
My Basic IPerson contains following Fields:

class ICompanyContact(Interface):
    """
    """
    website = schema.TextLine(
        title=_(u"label_website", default=u'Website'),
        description=_(u"help_website", default=u''))
    email = schema.TextLine(
        title=_(u"label_email", default=u'E-Mail Adress'),
        description=_(u"help_email", default=u''))
    phone = schema.TextLine(
        title=_(u"label_phone", default=u'Phone'),
        description=_(u"help_phone", default=u''))

And I want to reuse all of this fields for
class ICompanyContact()
class ICompanyContactApplication()

And later the form inputs should be saved in an dexterity item...

What about making the fields behaviors and add the different behaviors to your content types ?

How about using a data grid field?

This was my first thought, but how can I save 3times the same field id (for example fname, surname or phone) and output them?

I have an example (remember to install datagridfield)

Uh, good idea - thank you!
But, I will prefer a "more standard" way, without any 3rd Party Tools


Anyway, I'll give that a try (because I have to finish it up :wink: )

class IContact(Interface):
    fname = schema.TextLine(
        title=_(u"label_fname", default=u'First name'),
        description=_(u"help_fname", default=u''))
    sname = schema.TextLine(
        title=_(u"label_sname", default=u'Surname'),
        description=_(u"help_sname", default=u''))

class IPerson(model.Schema, Interface)
    form.widget(company_contact=DataGridFieldFactory)
    company_contact = schema.List(
        title=u"Company contact",
        value_type=DictRow(
            title=u"Contact",
            schema=IContact),
        required=False)

    form.widget(company_contact=DataGridFieldFactory)
    application_contact = schema.List(
        title=u"Application contact",
        value_type=DictRow(
            title=u"Contact",
            schema=IContact),
        required=False)
1 Like

Plone Foundation Code of Conduct