espenmn
(Espen)
October 29, 2019, 3:59pm
1
Two questions:
Is there any other widget than CheckBoxFieldWidget and InOutWidget that could work with a (MultiSelect) List field inside a DictRow
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'
mtrebron
(Norbert )
October 21, 2020, 2:24pm
2
@espenmn did you ever work out how to disable auto_append (and friends) in either the schema or the interface?
espenmn
(Espen)
October 21, 2020, 2:38pm
3
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
mtrebron
(Norbert )
October 21, 2020, 4:10pm
4
I was just able to customize the other properties by doing this:
@implementer(z3c.form.interfaces.IFieldWidget)
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
@provider(IFormFieldProvider)
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...
mtrebron
(Norbert )
October 21, 2020, 4:30pm
5
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.
espenmn
(Espen)
October 22, 2020, 9:54am
6
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 )?
mtrebron
(Norbert )
October 22, 2020, 10:17am
7
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.