Skip to main content
← Data, API & Backend
Data, API & Backend September 2, 2024 · 2 replies

Enabled/disable option selectors based on API response

Archived from the Bravo community forum (2021–2026). Some answers may refer to older versions of Bravo.

Hi there!

I’m trying to build a multiple option selector that enables/disables options based on the available combinations. For example, imagine the response below where there’s multiple combinations of size + color values, but not all the combinations are available. So for instance `Blue` + `XS` is available, but that size is not available in `Black`.

[
    {
        ...,
        "variant_values": [
            {
                "attribute": {
                    "id": 1,
                    "name": "Color"
                },
                "value": {
                    "id": 1,
                    "name": "Black"
                }
            },
            {
                "attribute": {
                    "id": 1499,
                    "name": "Size"
                },
                "value": {
                    "id": 15547,
                    "name": "XXXS"
                }
            }
        ]
    },
    {
        ...,
        "variant_values": [
            {
                "attribute": {
                    "id": 1,
                    "name": "Color"
                },
                "value": {
                    "id": 2,
                    "name": "Blue"
                }
            },
            {
                "attribute": {
                    "id": 1499,
                    "name": "Size"
                },
                "value": {
                    "id": 15547,
                    "name": "XXXS"
                }
            }
        ]
    },
    {
        ...,
        "variant_values": [
            {
                "attribute": {
                    "id": 1,
                    "name": "Color"
                },
                "value": {
                    "id": 1,
                    "name": "Black"
                }
            },
            {
                "attribute": {
                    "id": 1499,
                    "name": "Size"
                },
                "value": {
                    "id": 15548,
                    "name": "XXS"
                }
            }
        ]
    },
    {
        ...,
        "variant_values": [
            {
                "attribute": {
                    "id": 1,
                    "name": "Color"
                },
                "value": {
                    "id": 2,
                    "name": "Blue"
                }
            },
            {
                "attribute": {
                    "id": 1499,
                    "name": "Size"
                },
                "value": {
                    "id": 15548,
                    "name": "XXS"
                }
            }
        ]
    },
    {
        ...,
        "variant_values": [
            {
                "attribute": {
                    "id": 1,
                    "name": "Color"
                },
                "value": {
                    "id": 2,
                    "name": "Blue"
                }
            },
            {
                "attribute": {
                    "id": 1499,
                    "name": "Size"
                },
                "value": {
                    "id": 15549,
                    "name": "XS"
                }
            }
        ],
        ...
    }
],

I’ve got 2 questions:

1. How can I show multiple option selectors dynamically? In the example there’s Color and Size, but it could have more attributes like for instance `Shape` with its own options (round, squared, etc).

2. How can I enable/disable options mutually. For instance:
- If I select XXXS, then both Black and Blue are clickable.
The UI could look like:
Size
XXXS | XXS | XS
Color
Black | Blue

- If I select XS, then only Blue should be clickable.
The UI could look like:
Size
XXXS | XXS | XS
Color
Black | Blue

Any idea on how this can be achieved?

Thank you in advance!

2 replies

Wrote something in this thread and want it removed? Request removal

Still stuck?

Ask the community on Discord

This archive is read-only. New questions, office hours and product updates now happen in the Bravo Discord.

Join the Discord