question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditionals in Field Arrays

See original GitHub issue

Scope: Schema / FormRenderer

Description: Would love the ability to put up conditionals within field arrays. Currently now the condition target is an exact path, working with field arrays the field will be an array [0], [1] etc, thus making it impossible to dynamically alter the condition based on every new “row” of field array directly in the schema.

Schema Short example code (disregard obvious type errors)

const fieldOptions = [...fieldTypeOptions];
const fieldSchema = [...schemaFields];
const searchField = {
    component: "field-array",
    name: "FieldArr",
    fields: [
        {
            FormFieldGridProps: { md: 12 },
            component: "autocomplete-async",
            label: "Field type",
            name: "FieldType",
            options: fieldOptions,
        },
        ...Object.entries(fieldSchema).map((entry) => {
            const [key, field] = entry;
            const target = fieldOptions.find((item) => item.value == key);

            return Object.assign(field, {
                FormFieldGridProps: { md: 12 },
                condition: {
                    when: "FieldType",
                    is: target ,
                    then: { visible: true },
                },
            });
        }),
    ],
};

The condition will not match since FieldType in the instance will be “FieldArr[0].FieldType” and continuing on the next added field array the target will be “FieldArr[0].FieldType”, making it impossible to dynamically match field array conditions based on the current instance “row”

Would be great if you could target the path based on the current index of field array, for example:

condition: {
    when: (fieldIndex, rowData) => `FieldArr[${fieldIndex}].FieldType[0]`,
    is: target,
    then: { visible: true },
},

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
tinkotvascommented, Oct 8, 2020

Working as intended!

1reaction
Hyperkid123commented, Oct 5, 2020

🎉 This issue has been resolved in version 2.10.0 🎉

The release is available on

Demo can be found here!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional fields in Array of type Object - Sanity.io - d||ell
Here's how you can work with conditional fields in array of type object - Sanity.io.
Read more >
How to use Conditional Logic on Array Forms - YouTube
Learn how to set up conditional logic on your Array form fields and email automation Watch more support videos on how to use...
Read more >
Big QUERY conditional statement for a field arrays
In big query, I am trying to show the array only if the array is not empty and else we return 0. The...
Read more >
Conditional Logic | Carbon Fields
The value of the field. It can be an array only when compare is IN , NOT IN , INCLUDES or EXCLUDES ....
Read more >
Field array - conditional rendering · Discussion #2593 - GitHub
I have a form where you can add/remove items, and where each item has a type field, and depending on this type ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found