palantir-foundryfoundry-slate

How can I reset a multiselect widget in Slate?


I need to clear the multiSelect widget's selected value via a button widget. I can add and remove different fields by hand easily, but so far I have not been able to get a button to work. Is this possible?


Solution

  • You will want to create an action for the user to reset all fields to a set of default values. The simplest pattern here is to define a v_defaults variable:

    { 
        "w_multiselectWidget_raw": ["a", "b"],
        "w_multiselectWidget_display": ["Alpha", "Beta"],
        "w_textInput": "default", ... 
    }
    

    Then, in the configuration for each widget, in the json definition (under the </> icon) you can template the particular version of the selected value property.

    For any widget that has a display value in addition to the raw value, make sure you template both the selectedValues and selectedDisplayValues:

    {
        ...
        selectedValues: "{{v_defaults.w_multiselectWidget_raw}}",
        selectedDisplayValues: "{{v_defaults.w_multiselectWidget_display}}",
        ...
    }
    

    The final step is to configure an event to trigger an update to the v_defaults variable, which will cause the dependency graph to update all the downstream nodes, which will include all the input widgets with templated selection values, and the selections will return to default.

    const defaults = {
        "w_multiselectWidget_raw": {{v_multiSelect_raw}},
        "w_multiselectWidget_display": {{v_multiSelect_raw}},
        "w_textInput": {{v_textInput}},
        "entropy": {{v_entropy}}
        ...
    }
    
    return defaults