How to hide a fieldset (tab) in Plone add/edit form
Asked Answered
C

2

5

I have some code in dexterity content type, as below:

form.fieldset(
    'transitionsLog',
    label=_(u"Transitions Log"),
    fields=['t_log']
)
form.mode(t_log='hidden')
t_log = schema.TextLine(
    title=_(u'Transitions log'),
)

In add/edit form, the field t_log hide but fieldset tab 'Transitions Log' still show at form, as above... enter image description here

I have no idea to hide "Transitions Log" tab in add/edit form,

How can I do ?

Contredanse answered 14/5, 2015 at 16:42 Comment(0)
M
6

Since the fields are still rendered in hidden mode, the fieldset still exists.

If you want to completely omit the fieldset you need to omit all fields in the fieldset. This can be achieved using the omitted directive form.omitted.

form.fieldset(
    'transitionsLog',
    label=_(u"Transitions Log"),
    fields=['t_log']
)
form.omitted('t_log')  # This will also omit your fieldset
t_log = schema.TextLine(
    title=_(u'Transitions log'),
)
Middlesworth answered 15/5, 2015 at 6:1 Comment(3)
well, if I want un-omitted this field in editForm, how can I do?Contredanse
You can achieve this by diving into the update method of your form.Middlesworth
could you give me some code at updateWidgets(self) or update(self) function?Contredanse
C
1

I find a right way as below to omitted field in Custom Add/Edit Form:

from plone.z3cform.fieldsets.utils import remove
...
def updateWidgets(self):
    remove(self, 't_log')
    super(CustomEditForm, self).updateWidgets()
Contredanse answered 19/5, 2015 at 22:33 Comment(1)
haha you were to fast ;-) Probably you should add your comment above as a different question and das this as an answer. imho it's not the same issue.Middlesworth

© 2022 - 2024 — McMap. All rights reserved.