Make empty field not editable

Is there a simple way to make a field 'not editable' if it is empty ?

In other words, if the content was created with field 'foo's value = 'bar', users can change it to 'somethingelse', but if the field was empty upon creation, it can not be edited.

Would be perfect if it can be done in XML (Dexterity TTW editor), but CSS could also be an option

I would use JS for this purpose by setting readonly=true on the related elements.

Is that better than hiding '#something .empty' with CSS ? (empty fields have a class of .empty')

Hiding and making something non-editable are two different things :upside_down_face:

True, but disabling javascript would do the same (?)

Then you can create your own form and add

from z3c.form.interfaces import DISPLAY_MODE

class MyForm(Interface):
    directives.mode(my_field          = DISPLAY_MODE,)


So I can check my_field with a condition and set display_mode base on that (?)

 if contex.my_field == "": # or  False or Null or None or whaterver
    display_mode='hidden'  # or 'display'

I would start reading here: Schema-driven forms — Plone Documentation v5.2
Package documentation: · PyPI and plone.z3cform · PyPI and z3c.form — z3c.form 4.4.dev0 documentation

Edit: to answer your question: no, to make a hidden field you would import HIDDEN_MODE
e.g. for a Text Widget: Text Widget — z3c.form 4.4.dev0 documentation