Dropdown multiple selection

Hi all.
I put a dropdown control into a page that allow to select multiple files from a directory in order to show their contents in a graph.
When you select the upper stick, all items are selected or unselected at the same time.
Unfortunately, this operation send output as end of selection without get out from the form.
By this way, ALL items contained into the directory is sended to next node.
There is a way to avoid that like : lock sending until I get out from the form OR get the output and truncate the array in a limited number of elements ?
Thanks at all for any help

Basically you can have function node after the dropdown node something like this

// you'll need to know total count of items 
// currently available in dropdown

// for this example let's pretend there is 10
const knownElementCount = 10

if(Array.isArray(msg.payload)){
    if(msg.payload.length == 0){
        //no items selected                
    }
    else if(msg.payload.length == knownElementCount){
        // all items selected
    }
    else{
        // some elements selected
    }
}

So you can make different decisions how to behave in those different situations

Thanks for the answer.
This is the first step can show me if the selected items are equal to zero, minus than 10 or more than 10.
In which way I can select only the first 10 elements in order to create a msg.payload with only these elements?

To get the first n elements of an array, use

const slicedArray = array.slice(0, n);

If the problem, as in my case, is extract only the first 8 elements, the function can be the following :

var arrax = msg.payload
msg.payload= arrax.slice(0, 8)
return msg;

Putting the function on dropdown output, limits the number of elements into output array, regardless of its complete lenght.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.