z3c.form.Datagridfield. Widgets and setting

Two questions:

  1. Is there any other widget than CheckBoxFieldWidget and InOutWidget that could work with a (MultiSelect) List field inside a DictRow

  2. Is it possible to disable disable 'auto append' for all fields or is the only option to

    def updateWidgets(self):
    super(EditForm, self).updateWidgets()
    self.widgets['interactions'].auto_append = False

for every 'Datagrid-field'

@espenmn did you ever work out how to disable auto_append (and friends) in either the schema or the interface?

No, I think I 'cheated' by forking some add on and change the defaults (settings)

Update: It might be that those settings was saved in / with a javascript

1 Like

I was just able to customize the other properties by doing this:

def VOCInfoGridFactory(field, request):
    A special widget constructor setting up widget parameters for DGF.
    widget = DataGridFieldFactory(field, request)
    widget.allow_insert = False
    widget.allow_delete = False
    widget.allow_reorder = False
    #widget.auto_append = False
    return widget

class IUrprodukt(model.Schema):
    voc_info = schema.List(
        title       = _(u'VOC EU Grenzwert Kennzeichnung'),
        description = _(u'Art und Grenzwert für Flüchtige organische Verbindungen gemäß Richtlinie 2004/42/EG'),
        required    = False,
        value_type  = DictRow(
            schema = IMaxVolatileCompoundsSchema
    directives.widget('voc_info', VOCInfoGridFactory)

class IMaxVolatileCompoundsSchema(Interface):
    voc_max_schedule = schema.TextLine(
        title    = _(u'Anwendungsbereich'),
        required = True,
    directives.widget('voc_max_schedule',   DGFTreeSelectFieldWidget)

    voc_max_category = schema.TextLine(
        title    = _(u'Kategorie'),
        required = True,
    directives.widget('voc_max_category', DGFTreeSelectFieldWidget)

    voc_max_class = schema.TextLine(
        title    = _(u'Klasse'),
        required = True,
    directives.widget('voc_max_class', DGFTreeSelectFieldWidget)

    voc_max_content = schema.Int(
        title    = _(u'Produkt Enthält Max.'),
        required = True,
        min = 0,
        max = 999,
IMaxVolatileCompoundsSchema.setTaggedValue('vocabularyName', 'mdb_theme.MaxVolatileCompounds')

This produces:

Code adapted from https://github.com/collective/collective.z3cform.dgftreeselect/blob/master/src/collective/z3cform/dgftreeselect/testform.py#L80

However, when I attempt to set auto_append to False my edit form's fieldsets stop rendering in separate tabs and the datagrid cannot be edited any longer...

After a bit more testing:

If the datagrid already contains a value, the page is rendered correctly. Looks like all that I need to do is to update my content by adding a default value to this new field.

A vague memory: does it help to set the fields of IMaxVolatileCompoundsSchema to required=False ?

PS: I used this for theme fragments. Do you think your approach would work without having registering a custom widget ( in zcml )?

I ended up setting the default values in my dexterity schema and made the field required instead of the grid cells. This last step was mostly for cosmetic effect.

With "custom widget" you mean the tree widget? I haven't tried with other widgets, but I guess you could add a custom factory that implements a standard widget in similar fashion. The only zcml registration I have for the tree widget is a data converter adapter, nothing out of the ordinary.