New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial values for any type #1581
Comments
Thanks for submitting this! It's obviously a feature that might be handy. We have no ETA on it as of yet, but feel free to follow this issue. |
@kmelve pretty please? |
I like the proposed solution from @ORBAT. I would also add that a nice addition would be to ensure that the document can override the default that is set in the type initialValue. |
I also look forward to a solution where we can add Initial values for objects. |
I would also love this to be resolved! |
This is all I want for Christmas |
+1 on initial values for objects as well 🙏 |
i++ |
I would like to be able to use an initial values for objects as well. |
+1 Yes, please :) |
+1 Looking forward to this!! |
+1 for initial values for objects, please. |
+1 for initial / default values for objects 🙏 |
+1 for would be very nice to set initial values for objects |
+1 for initial / default values for objects 🧑🍳 |
This would really be awesome! Are there any workarounds? |
+1 on this for sure, major pain point |
+1 for this. Any idea where this is on the roadmap? |
@kmelve Would you accept a PR for this? On the surface it seems fairly straight-forward, or are you expecting it to be more complex? |
Or @rexxars equally 🙂 ^^^ |
Given how great everything else is, I was super surprised to see default values / initial values aren't possible for objects. Would be great to have a solution to this! |
Hi folks! We agree that this feature makes sense. Offering a PR is super generous @joshfarrant, but we will do this one internally as it's tied to code paths that we want to clean up a bit. It's on the prioritized backlog though! |
Any updates here? We really need this! Are you sure you don't want to accept a PR? |
Hi everyone! Thank you for your patience. Just wanted to let you know that we have a PR shaping up for this issue. We'll update this issue with specifics soon. |
If you are keen on trying out this feature before we ship it officially, we just cut a canary release from PR #2444. You can install it in your Studio by running: sanity upgrade --tag=canary --save-exact It should work very much like the solution initially outlined by @ORBAT. You can see a full example of a document that uses different variations of initial values here: https://github.com/sanity-io/sanity/blob/d750f0a9e2c51984d5349edc67987ceb04e37413/examples/test-studio/schemas/initialValuesTest.js |
Initial value support for any type has shipped in v2.10.0. Thank you all for your patience and valuable input! |
@bjoerge literally came to check for an update on this! nice surprise :) |
@bjoerge this is a great addition! However, it appears that the For a newly created document, this could pass in the document as created using Initial Value Templates. For nested objects (or arrays of objects) this is much more useful, since you'd be able to infer what to add there based on the main document. For example, when adding to a list of attributes (array of objects), you'd be able to lookup the In short, for consistency with the other functions in Sanity (custom validation, uniqueness etc.) it would make sense to provide a |
Problem
If a document field is of some custom type that always has the same default, I have to respecify those defaults in every document that uses it. As an example:
Proposed solution
Both
someDocument
andanotherDocument
would have the initial value{ paidContent: true }
.Alternate solutions
E.g. Exporting the initial value, and then importing & merging it with document initial values. More brittle, requires users of the type to do it manually
The text was updated successfully, but these errors were encountered: