Tag Selection

Hi,
I wanted to know if there is any way when I press button 1 a specific TagSelection button is activated (Example Green).Can you help me?

Francisco, you can set it either by the selectedIndices property which accepts an array of numbers that specifies the index of the item(s) to be selected, or the value property, which takes a string array of values. An example of how to apply the selectedIndices to your example:

$w("#TagSelection").selectedIndices = [1];

It’s 0-based, so to select the red tag would be [0] and blue would [2]. To select all of them would go like this:

$w("#TagSelection").selectedIndices = [0,1,2];

Perfect!Thank you very much.

How do I get back from deselecting the item (green) when I press button 1?

To deselect all tags, assign an empty array.

$w("#TagSelection").selectedIndices = [];

And how do I deselect a specific one (Green)?

@franciscolou22 That is a little more involved because you need to capture the state of the selections first in an array, then remove the green one from it using the JS splice function, and then re-apply.

    let selIndices = $w("#TagSelection").selectedIndices;
    const index = selIndices.indexOf(1);
    if (index > -1) {
        selIndices.splice(index, 1);
        $w("#TagSelection").selectedIndices = selIndices;
    }

You may find it easier to work with the value property. I don’t know what value you assigned to the selection tag with the label “Green”, but this is how it would be done if the value of that tag was also “Green”.

    let selValues = $w("#TagSelection").value;
    const index = selValues.indexOf("Green");
    if (index > -1) {
        selValues.splice(index, 1);
        $w("#TagSelection").value = selValues;
    }

Perfect!Thank you very much.