I'm looking to handle conditional fields in Volto and Dexterity, ideally it should be possible to both hide fields and ensure that they are conditionally required based on a dropdown selection.
A good example might be a book catalog system in Volto where different types of publications require different metadata fields. I need both the visibility and required status of fields to change based on a "Publication Type" dropdown selection.
For example, when "Book" is selected, the ISBN field should be both visible and required, but ISSN should be hidden. When "Journal" is selected, ISSN should be visible and required, but ISBN should be hidden.
Currently, my Dexterity XML schema looks like this:
<field name="publication_type" type="zope.schema.Choice">
<title>Publication Type</title>
<values>
<element>Book</element>
<element>Journal</element>
<element>Conference Proceedings</element>
</values>
</field>
<!-- Book-specific fields -->
<field name="isbn" type="zope.schema.TextLine">
<title>ISBN</title>
<required>False</required> <!-- Should be required only for Books -->
</field>
<!-- Journal-specific fields -->
<field name="issn" type="zope.schema.TextLine">
<title>ISSN</title>
<required>False</required> <!-- Should be required only for Journals -->
</field>
<!-- Conference-specific fields -->
<field name="conference_date" type="zope.schema.Date">
<title>Conference Date</title>
<required>False</required> <!-- Should be required only for Conference Proceedings -->
</field>
Required behavior should be:
- For Books:
- ISBN is required
- ISSN and Conference Date are hidden
- For Journals:
- ISSN is required
- ISBN and Conference Date are hidden
- For Conference Proceedings:
- Conference Date is required
- ISBN and ISSN are hidden
What's the recommended approach for implementing both conditional display AND conditional requirements in Volto? Does this need to be handled on both frontend and backend? Should I just abandon Dexterity totally for this (I have a need to provide an api for rest-based clients so I suspect that will mean keeping dexterity)?