Automatically Changing Field A Based on Field B

4 replies
Last updated: Jan 18, 2023
Is the current/best way to change field A based on field B (with live updates) still to use a listener on the field and then a patch or mutation?
What kind of change do you mean? You can use the
hidden
and
readOnly
keys. Or are you looking at doing something more complicated?
For example, when field A is set to "title", set field B to "title something else"
If you want it to automatically change, then you will still want to use a listener and a patch. Otherwise, you can do something like a document action that updates the value of B when the document is published.
Well, they'd want to be able to change it, so yeah, a listener. It's tricky because we need to fill if empty, otherwise, don't change it. In our situation, it's
<title>...</title>
tag vs. "page title" in
<h1>...</h1>
. The use case is that it's almost always the same, but not always, but it's a pain for them to enter twice, so...thanks again,
user M
you're our rock (star)!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?