Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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

default discord avatar
a16erblech2 years ago
2

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?

  • discord user avatar
    tylandavis
    2 years ago

    hey

    @693477237764128869

    , 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.

  • default discord avatar
    a16erblech2 years ago

    hi

    @783701636165402624

    thank you for your answer! For the bigger picture, i need to create a survey-app where you have different 'decision' paths. The survey consists out of multiple/single choice questions but also different kind of components - that i dont know yet. Each Question is One Page and could be a Question or just content. With every answer you could jump to a different question, so its likely possible if you choose answer x that you jump over 2 questions or just the next page with content. So i want to create something where you can set a condition for a relation to the next Question. So i could say "if the answer to question 1 is 2 then jump to 2" but also "if the answer is bigger/smaller than 42 then jump to ..'" and so on. I also want to make it possible that you can combine it with And & Or to be flexible for every case and for that i thought about using the array - cause often times its just 1 condition for the nest Question and i would only need more if i want to combine it, so only when i select and/or i could set another one.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.