Select to view content in your preferred language

Remove Option from Toolbox Parameter Value List if Selected

1003
10
Jump to solution
11-11-2022 01:09 AM
Labels (2)
RichardHowe
Occasional Contributor III

I have a tool which has a string parameter with a predefined value list filter, allowing the user to select multiple options from a dropdown list in the GUI.

However, when they select one option, I would then like that option to be removed from the list which they  choose the next option from. Is this possible, and if so how? In an ideal world it would be the default behavior, because I struggle to think of why you would want to put the same option in twice as a user, but you can.

In the image below the Value List filter comprises A, B, C and D. As you can see the user has chosen A for the first entry and B for the second. I would like the options for the next entry to just be C and D, so they can't errantly pick A or B again...but that isn't the case.

RichardHowe_0-1668157826483.png

 

I feel perhaps some kind of validation is probably the answer to this, but I can only find documentation to make individual parameters dependent on another parameter, not on entries for the same multi value parameter.

0 Kudos
10 Replies
tyler_fossett
New Contributor

Happy to help!  I did notice room for improvement with original code... if the user exhausts the list to the point where no more items should be shown, the original code I provided shows the full list again if the user keeps trying to select values.

This can be solved by replacing line 11 in the original code with lines 9-12 below.  I added a line to my execute function as well so it ignores the space placeholder.

def updateParameters(self, params):
    filtervals = ['A', 'B', 'C']
    try:
        paramvals = params[0],valueAsText.split(";")  
        for val in paramvals:
            filtervals.remove(val.replace("'",""))

        ## ******************************************
        if not filtervals:
            params[0].filters[0].list = [" "]
        else:
            params[0].filters[0].list = filtervals
        ## ******************************************

    except:
        pass