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?
Asked
Active
Viewed 128 times
1 Answers
3
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

Max Magid
- 245
- 1
- 8
-
2Note that this event will need to assign a random value, normally I just use `Math.random()` for the "entropy" property. This ensures that the Slate dependency graph identifies a change in the node status and reevaluates the dependency graph, which is what actually updates the widget values. You can find an example of this resetting pattern in the Foundry Training and Reference Project on any Foundry instance in the Slate Reference Example folder. – Logan Rhyne Dec 14 '22 at 15:33