Widgets: Hiding IVersionable.versioning_enabled' (from Settings)

How can I hide the 'versiong_enabled' widget, or alternatively, the whole 'settings' fieldset.

def updateWidgets(self):
    super(ActionItemsAddForm, self).updateWidgets()
    self.widgets['related_item'].mode = interfaces.HIDDEN_MODE
    #also works
    self.widgets['IVersionable.changeNote'].mode = interfaces.HIDDEN_MODE
    #Gives Key Error
    self.widgets['IVersionable.versioning_enabled'].mode = interfaces.HIDDEN_MODE

I assume there must be another way of hiding it, since it is not in standard fieldset / group (especially since self.widgets only returns the widgets in 'Standard' tab).

Disable the behavior?

They want the behavior, they just dont want users to change the settings on individual content items. Maybe I could just change permissions, but it might be 'just as difficult'.

Turn off the behavior (which adds the fields), but turn on the automatic versioning policy (so that new revisions will be created even when the fields aren't there). The versioning policy setting is in the Content Types control panel once you select a specific content type (classic UI only).

Thanks. Does that mean that it is impossible to hide any field that comes from a behavior unless they are in the 'default fieldset' (I can disable ['IBasic.description'] and other that are in 'default fieldset'.

Could it be that I need to update groups or fieldset or something similar?

PS: I probably need it for some others as well so it would be nice to know)

Probably something like self.groups[0].widgets['IVersionable.versioning_enabled'].mode

You'll need to figure out which index is the correct group, and you'll need to set it from the update method rather than updateWidgets, after calling the super's update method, which is where the group forms for fieldsets are instantiated. (z3c.form/src/z3c/form/group.py at master · zopefoundation/z3c.form · GitHub)

Few options:

  1. Drop the fields with Diazo or hide the tab and fields with some css?

  2. Omit the fields with this.fields.omit(...) in updateWidgets

  3. Drop the behavior but enable the underlying stuff.
    The functionality seems wired up to IVersioningSupport, not the IVersionable behavior. You could try to disable the behavior and make the content class have IVersioningSupport too.

I'd try hiding with css first :smiley:

Thanks a lot, that was the part I did not get ( self.groups[0].widgets does on exist in updateWidgets.

So, the following code works

def update(self):
    super(ActionItemsAddForm, self).update()

    self.groups[4].widgets['IVersionable.versioning_enabled'].mode = interfaces.HIDDEN_MODE
    self.groups[4].widgets['IAllowDiscussion.allow_discussion'].mode = interfaces.HIDDEN_MODE

    for group in self.groups:
        if group.__name__ == 'settings':
            self.groups[4].widgets['IVersionable.versioning_enabled'].mode = interfaces.HIDDEN_MODE
            self.groups[4].widgets['IAllowDiscussion.allow_discussion'].mode = interfaces.HIDDEN_MODE

For reference, I noticed that group has 'mode' (which was 'input'. It might be possible to hide the whole fieldset taht way(?) There might be an alternative 'hack': removing the label:

#Not working
group.mode = 'hidden'
#Hides the 'tab'
group.label = None

I have always missed the name of the tab as a css class. Currently, they use 'autotoc-[number]', which might change. (in my case, the site is under development, so there might be more or less tabs / fieldsets, if there was a class (.tab-settings or something similar) this would be quite straightforward. (PS: This answer is also based on 'that I thought empty fieldsets would not render (the tab). In my case, the fieldset would 'some places/sections' be empty and other not) .

This seems to work for demo.plone.org . ymmv and a test is always needed.

.fieldname-form.widgets.IVersionable.versioning_enabled {display: none}
or document.getElementsByClassName('fieldname-form.widgets.IVersionable.versioning_enabled')[0].remove()

Might need an additional selector for only target the right content type. Might be saner to do whatever you're currently doing.

True, but it could have been 'cleaner', and for example hide tab if content is (more or less) empty.

The fieldset itself has 'proper classess',


It would be practical if the tabs also had similar CSS classes.