🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Setting a notice message for a field in Sanity and customizing its color

13 replies
Last updated: Jun 23, 2023
Hello there,Please is it possible on sanity to set a notice message for a field that is showed everytime independently of rule validation ?
Jun 23, 2023, 1:03 PM
Jun 23, 2023, 1:08 PM
Thank you, I did it and it is showing
Jun 23, 2023, 1:13 PM
Now is it possible for a datetime to show notice message with a specific colour please ?Like this,
Jun 23, 2023, 1:15 PM
I found a way to use custom.css but when I try I'm stuck here:
Jun 23, 2023, 1:17 PM
That looks like a validation message not a description…
But I think if you want to do that you’ll have to create a custom component
https://www.sanity.io/docs/component-api
Or do it with validation
https://www.sanity.io/docs/validation which is probably the better choice here.
You could have a description that says “Enter the match time in your local time.” And then add a warning/error if it’s not what you expect? Because making a description red like that signals (to me at least) that there’s an error but the date input is empty so why would it be red?
Jun 23, 2023, 1:21 PM
I tought the same thing but the product owner wants it like that
Jun 23, 2023, 1:26 PM
I personally would push back but that’s me. So you’ll have to go about creating a custom component and maintaining that. Because className doesn’t look to be a valid option for datetime https://www.sanity.io/docs/datetime-type
Jun 23, 2023, 1:31 PM
Ok thanks
Jun 23, 2023, 1:35 PM
The
description
field can take a React component, so you could try setting it to something like:

description: (
  <>
    <div style={{ color: 'red' }}>This is important text.</div>
  </>
),
// rest of schema...
Jun 23, 2023, 2:37 PM
Tried but it is not working
Jun 23, 2023, 3:13 PM
Working well, Thanks. was using ts file instead of tsx
Jun 23, 2023, 3:17 PM
Given those errors, you’re probably in a .ts file. It will need to be tsx.
Jun 23, 2023, 3:17 PM
Thank you very much
Jun 23, 2023, 3:17 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?