How to hide a field if an initial value is passed in a specific context.

4 replies
Last updated: Feb 12, 2024
Does anyone know how to hide a field if you're in a context where there is an initial value?
Feb 12, 2024, 1:14 PM
What I'm trying to do is to hide a field if an initial value is passed. Meaning if that the field has a predetermined value, the display of the field is not needed.
Feb 12, 2024, 1:24 PM
I ended up doing something very ugly! I checked the URL to see if I was in the context that I was looking for.
Feb 12, 2024, 1:52 PM
I have an entity called person, and the person must belong to a company. The person can be edited from the root of the menu, but it can also be edited when going to a company, and be selected as a sub-page. This means that the reference-field to the company on the person would only be relevant when not editing from a sub-page.
Feb 12, 2024, 1:53 PM
Ugly AF, but it works, and it will work as long a the URL structure does not change.
Feb 12, 2024, 1:54 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?