Menu Builder best practices (limiting nesting depth)

Hello,

I’m trying to implement a ā€œMenu Builderā€ in DatoCMS.

Currently, I have a Menu model with a field that links to multiple MenuItem records (another model). Each MenuItem can also contain a list of nested MenuItem entries, which allows me to build a two-level menu structure.

This setup works fine, but I haven’t found a way to limit the nesting depth in the admin interface. Since I only need two levels, I’d like to prevent editors from creating a third level by mistake.

Is there a recommended way to enforce a maximum nesting depth, or a better overall approach to handling menus like this in Dato?

Thanks in advance!

Hello @deven

at the moment we don’t have a way to enforce a validation like the want you need. We have this feature request: Custom validation that you can upvote that could solve your problem down the line. It’s something that we believe should be done, so it might be added at some point.

Meanwhile, the only idea that I have is to use modular blocks instead, where you can limit the type of blocks that you can add, so you can have ā€œfirst level menuā€ and ā€œsecond level menuā€ blocks and you can limit it this way.

It’s not the same as using a different model, but maybe it can solve your issue?

The workaround works for me, thank you!

1 Like