Collective.easyform with repeatable fields?

I would like to have a form (collective.easyform) where the user can add a subset of the fields multiple times.
This is not new (see Using patternslib clone for repeating fields in a formbuilder
and PloneFormGen: Datagridfields - Make it possible to add multiples of one form field type) but I could not find an example of how to add repeatable fields.

If this is possible can someone give an example?

I can't give you an example, but I can tell you that I managed to use collective.z3cform.datagridfield in a Plone 5.2 setup. The same code did not work on Plone 5.1.
This was done as a test when I updated some add-ons to Python 3, so I dont have the code

As far as I remember I defined the 'value_type' in an add-on and then used that in easyform.

This is what I think I did :

In my add-on (interfaces.py):

class IMySchema(interface.Interface):
    something = schema.TextLine(title=u"Something")
    something_else = schema.TextLine(title=u"Something Else")

In easyform:

repeating_fields = schema.List(title=u"Some name",
value_type=DictRow(schema=my.addon.interfaces.IMySchema))

Please note that not all field types work (if 'something' is a Reference, an Image or a File (blob) it will not work

Thx @espenmn

I am not sure where in easyform to add

repeating_fields = schema.List(title=u"Some name",
value_type=DictRow(schema=my.addon.interfaces.IMySchema))

I have tried to modify xml schema of a form. It looks like that:

<model
  xmlns="http://namespaces.plone.org/supermodel/schema"
  xmlns:easyform="http://namespaces.plone.org/supermodel/easyform"
  xmlns:i18n="http://xml.zope.org/namespaces/i18n"
  i18n:domain="collective.easyform">
  <schema>
    ...
    <field name="test" type="zope.schema.List">
      <description/>
      <required>False</required>
      <title>My title</title>
      <value_type type="collective.z3cform.datagridfield.DictRow">
          <schema>unimr.formspolicy.interfaces.IMySchema</schema>
      </value_type>
    </field>
  
  </schema>
</model>

But when I try to add a row to my form

I get "TypeError: AutoExtensibleSubformAdapter() takes no arguments".

Tested with: Plone 5.2rc1 (5202)

Maybe it helps to state the widget

I do not know how to state a widget correctly for supermodel. All I found is "ui:widget".

I have tried things like this - but without success (error message is still the same):

 <field name="test" type="zope.schema.List" ui:widget="collective.z3cform.datagridfield.datagridfield.DataGridField" >
    <description/>
    <required>False</required>
    <title>My title</title>
    <value_type type="collective.z3cform.datagridfield.DictRow">
        <schema>plone.app.querystring.interfaces.IQueryOperation</schema>
    </value_type>
</field>

I can't remember about datagridfield, but the syntax for defining widgets is one of these (remove one of the defenitions… not sure which):

<field name="text" type="plone.app.textfield.RichText" marshal:primary="true"
      form:widget="plone.app.z3cform.widget.RichTextFieldWidget">
      <form:widget>plone.app.z3cform.widget.RichTextFieldWidget</form:widget>
  <title>Text</title>
</field>

PS: Just to be sure: It is very important that you install datagridfield from the add-ons control panel

See

Thx at all (@espenmn: I really forget to install datagriedfield from control panel.)

Finally this works:

<?xml version='1.0' encoding='utf8'?>
<model xmlns="http://namespaces.plone.org/supermodel/schema" xmlns:easyform="http://namespaces.plone.org/supermodel/easyform" xmlns:i18n="http://xml.zope.org/namespaces/i18n" xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" i18n:domain="collective.easyform">
  <schema>
...
    
    <field name="test" type="zope.schema.List">
     	<form:widget type="collective.z3cform.datagridfield.datagridfield.DataGridField">
            <klass>datagridwidget-row</klass>
     	</form:widget>
        <description/>
     	<required>False</required>
    	<title>My title</title>
        <value_type type="collective.z3cform.datagridfield.DictRow">
    	    <schema>unimr.formspolicy.interfaces.IMySchema</schema>
        </value_type>
    </field>
   </schema>
</model>

Now I can add repeatable fields to the form. But the inserted values are not show on thanks page and not send via email. There is just "<NO_VALUE>" shown.

Do I have to implement a new form action if I use repeatable fields?

The repeating fields are saved as lists (I think), so you will have to 'loop thought them'.

If you search this forum for data grid field, you might find the answer (this has been discussed before)

Please just submit a patch to the existing actions if they don't support lists. You might need to make changes to both the email adapter and the save data adapter and to the thank you page. Creating new plugins just creates confusion.

Please just submit a patch to the existing actions if they don't support lists.

Well - that`s not so easy. We (@zopyz and I) were not able to find the reason why "<NO_VALUE>" is set. While debugging widget_value seems to be set correctly at z3c.form.widget but thanks page shows "<NO_VALUE>"

Has someone an idea or hint?

I did a quick test with the save adapter, and it looks like the fields are saved, but not correctly. (I used an existing model.schema definition, maybe that has something to do with it).

class IMySchema(model.Schema):
"""example fields to be used with easyform and fragments"""
    something = schema.TextLine(title=u"Something")
    something_else = schema.TextLine(title=u"Something Else")´

Anyway:

  1. I added it to easyform
  2. I deleted the mail adapter and added a save adapter
  3. I got this

UPDATE: By the way: the CSV is exported "to this":

espen@medialxx.no,sdfasdf,asdfasdf,"[{'something_else': u'uuuuu', 'something': u'xxx'}]"

We were just trying to fix thanks page.

At first glace save adapter looks ok but when you modify a value and save it the values from repeatable fields are removed. ;-(

Do you mean the user that fills out the form, or when you modify it later ?

When you modify a value at the form at your screenshot and save it the values are lost.

It looks to me that 'the form at my screenshot' is not using the data grid-widget, but a 'multi-widget'. I am not sure if this is related to the thanks page and mailer