#How can i display 'add Row' in an Array only with a set condition?

1 messages · Page 1 of 1 (latest)

rare ravine
#

Lets say i have an array field and i want to display the 'add row' only when i check a checkbox or use a Select-field. Is this possible?

const Example: CollectionConfig = {
    slug: 'example',
    fields: [
        {
            name: 'row',
            type: 'array',
            labels: {
                plural: 'rows',
                singular: 'row',
            },
            fields: [
                {
                    name: 'headline',
                    label: 'Headline',
                    type: 'text'
                },
                {
                    name: 'condition',
                    label: 'Add another one',
                    type: 'select',
                    defaultValue: 'no',
                    options: [
                        {
                            label: 'Yes',
                            value: 'yes'
                        },
                        {
                            label: 'No',
                            value: 'no'
                        }
                    ]
                }

            ]

        }
    ]
}
#

How can i display 'add Row' in an Array only with a set condition?

proper viper
#

hey @rare ravine , it might help to explain your pattern a bit more here. In general, this sort of functionality could easily run into issues if you had rows with contradicting values for the condition field.

#

Ideally any conditions applied to the array should come from the array config itself, not one of its rows, but you may have a use case where something like that would make more sense.