How to populate a field's defaultValue
based on another collection?
#9162
ViktorShev
started this conversation in
General
Replies: 1 comment 3 replies
-
Hey @ViktorShev, So the way I would handle this would be via a Custom Field Component. You would fetch the related collections' multipliers and the set the value as needed, and you would do this work prior to the user being able to edit (which makes me believe that you would have a field structure such that the initial component is a RSC, and then drill that fetched data down to a client component). A custom Text/Number field would do this no problem. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I've been trying to figure this out for a couple of days now and I'm kind of running out of ideas, so wanted to ask if anybody has done this before.
My use case is simple:
I have the following data structures:
Client
Project
(has a relationship toClient
)Estimate
(has a relationship toProject
, has manyMilestone
s)Milestone
(has manyEpic
s)Epic
Client
has a field calleduncertaintyMultipliers
which is an object of the structure:{ low: number, medium: number, high: number, extreme: number }
and
Project
has the same thing, but they act as overrides:uncertaintyMultipliersOverrides
. (A project's uncertainty multipliers override the client multipliers).My issue arises here (checkout the TODO comment):
What I'm trying to achieve is basically: an Epic's DEFAULT uncertainty multiplier should be the "Low" multiplier of either the project or the client, depending if it's being overriden or not, think of it this way:
defaultValue: project.uncertaintyMultipliers.low ?? client.unceratintyMultipliers.low
I have figured out that
defaultValue
can be a function even though it is not typed as such, and that it receives one argument which is an object containing the current user.I have tried many ways of getting my hands on the Epic's ID to then to make a search for the project it belongs to and get the configured multipliers for the respective project or client and then set the default value to the
low
multiplier, but so far I could not figure it out, is there a way to do this?The current thing I'm trying is using a custom component for that field and doing the fetching there, since I can access the Epic's ID through the URL, but honestly, it's not a solution I'm too content with.
It would be AMAZING if the
defaultValue
property would receive information about the current item being viewed, like its ID, since Payload is already aware of it when fetching the item's data from the DB to display it on screen.Thanks in advance.
Versions:
Beta Was this translation helpful? Give feedback.
All reactions