Primary model with variants

I have a product model with slight variations, requiring some fields to be shown or hidden depending on the chosen variant. I initially considered using the Conditional Fields plugin with a dropdown to select the variant type.
However, the plugin doesn’t support required fields, making saving impossible if a required field is hidden. Additionally, different variants may need different validation rules.

Common Fields
- Name
- Product type
- Price
- more fields and blocks
Variant A
- Field A
- Field B
- Field C
Variant B
- Field A
- Field D
and so on

Most of the model data is managed using Blocks. I attempted multiple blocks dropdowns, but the lack of fieldset support in Blocks creates a poor user interface.

Potential Solutions:

  • Create new models for each variant: This isn’t ideal, as we may have 10+ variants.
  • Develop a custom validation plugin: This could be time-consuming.

Are there alternative approaches to achieve this functionality, ideally while maintaining a good user experience and avoiding excessive custom development?

Hi @StoyanDelev1,

Welcome to the Dato forums!

Sorry, complex conditional field hide/show logic like that is indeed a limitation in our system currently – especially if they need custom validation requirements. It could be a feature request (happy to convert this into one for you), but it’s not a very common request, so it might take a while :frowning:

There are some flawed workarounds you can explore… none are perfect and all have tradeoffs, but they might be worth considering, depending on your needs:

  • (As you already explored) Probably using blocks would be the most straightforward approach, if turning off the validations is an option
  • Custom models (like you said): Cleaner for the editors, more hassle for the developers
  • Instead of a custom validation plugin, how about a simple JSON field with a custom field editor plugin instead? That way you have 100% control over a few form fields (created by you in React or JS using whatever forms solution you want, including our own Forms UI widgets) and you can validate them however you want (frontend only). Then it just gets saved to that JSON field in whatever schema you like.

I don’t know if you’d consider that “excessive” (it’s probably a day of dev work?), but that’s all I can think of right now. Sorry, I know it’s not a perfect solution. Would still be happy to convert this into a feature request for you, if that would help?