First please consider the example for a custom add/edit form in the DX-docu
Then you are able to hide a field in the updateWidgets method of the form.
Example Code (not tested):
from plone.dexterity.browser.add import DefaultAddForm
from z3c.form import interfaces
class AddForm(DefaultAddForm):
def updateWidgets(self):
super(AddForm, self).updateWidgets()
if my_condition:
self.widgets['myfield'].mode = interfaces.HIDDEN_MODE
Since you have to do the same in the add
and edit
form, you could create a mixin class with your customization.