-
Notifications
You must be signed in to change notification settings - Fork 260
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
Using resolveFields for array. #499
Comments
This is a good question, ands something I overlooked in the initial implementation. Here are some suggestions:
Here's an example of the custom field approach (untested) 👇 import { AutoField } from "@measured/puck";
const config = {
components: {
Example: {
fields: {
myArray: {
type: 'array',
arrayFields: {
data: {
type: "custom",
render: ({ value, onChange }) => {
if (value.myCondition) {
return (
<>
<AutoField
field={{ type: "radio" }}
onChange={(fieldVal) => onChange({...value, myCondition: fieldVal })}
value={value.myCondition}
/>
<AutoField
field={{ type: "text" }}
onChange={(fieldVal) => onChange(fieldVal)}
value={value.myText}
/>
</>
);
}
return (
<AutoField
field={{ type: "radio" }}
onChange={(newVal) => onChange({...value, myCondition: newVal })}
value={value.myCondition}
/>
);
}
}
}
}
}
}
}
}; Would be curious to know if that works for you, and how/whether to extend |
Using no.2 approach is a definite fix (really appreciate this, does it for me, yes), but it is limited to just that one. I guess resolveFields would be a better choice (even for me) considering it is a general approach for every array fields. I haven't used much of those readOnly fields so don't know how I can override fields to also consider the usecase of readonly. And I am overriding everything right now, so would need something like this:
while overriding:
the worst thing here is that the arrayFields is constant for each item. Here one needs something like : My naive need: resolveField for array only so it becomes:
|
How can I use resolveFields api for an array. I want to look at the data and if a condition on any item of the array is satisfied, I want to do something with the fields of that item only.
ps: To make it more difficult, I have overriden the array field, so I am recursively rendering the overriden fields (have overriden all fields) to cover each type whatever comes.
The text was updated successfully, but these errors were encountered: