Programatically clean selection in MultiSelectField based in ToggleButton

Hi all, i have a MultiSelectField and i want to change its values acording to a ToggleButton. The problem is when i use to togle button to change the list values of the multifield, if previously there are values selected, those same values still will appear after the list change, and viktor will tell me that there is an error with the multifield

THis is the multifield

tab_r.section_3.input_3 = MultiSelectField("Basic", options=basic_report_options)

This is the function that fills the options in the multifield

def basic_report_options(params, **kwargs):
    # This is the toggle button
    es_calculo_cimentacion_profunda = params.tab_p.section_1.cimentacion_profunda

    if es_calculo_cimentacion_profunda:
        return ["Test1", "Test2", "Test3"]
    else:
        return ["Joint", "Deep (m)","B_BC (m)","B_EQ (m)","B_Sett (m)","B_Ex (m)","L_Ex (m)","Total_Sett (m)"]

For example, if the switch is off this are the options available, and i select two

image

If now i press the switch to on, the new list appear but the previously selected items are still visible and viktor says thare there is an error with the input

image

How can i clean the selection of the list before changing its values?

Hi Geomasticer,

What you are describing is the expected behaviour of the multi-select field. The reason that we have chosen for this behaviour is that the selected values of the multi-select field are remembered in case the options dynamically change for example from a=>b=>a. Else some values would be erased quietly.

If you want to erase the values of the MultiSelectField, you can use the SetParamsButton to set values of parameters. In your case however, it might be better to add two MultiSelectFields to your parametrization, and show them conditionally with the β€˜visible’ parameter on the Field. This way only the relevant MultiSelectField will show.

Hope that helps!

1 Like