palantir-foundryfoundry-slate

Slate Foundry : Modify parameter of a Dropdown programmatically


In Slate foundry, I would modify parameter of a Dropdown programmatically. Change the display value or disable value. But it doesn't work.

My code

const select ={{w_selectEndMonthYear}}
select.selectedValue = "202201"
select.selectedDisplayValue = "January 2022"
select.disabled = true
console.log({{w_selectEndMonthYear}})
return {{w_selectEndMonthYear.selectedDisplayValue}}

in my console, I have

{selectedDisplayValue: 'January 2022', selectedValue: '202201', disabled: 'true'}

It seems good, but neither the return nor the display of the widget changed

Thanks for your help


Solution

  • You're on the right track - to template the selected value of a dropdown list programmatically you need to change to the </> tab of the dropdown widget configuration and use Handlebars to provide a valid default selection for both the the selectedValue and selectedDisplayValue parameter.

    Note that you cannot set widget properties from inside a Slate Function. You need to return the value (or a json object with multiple values to reference) and then use a Handlebar statement in the widget configuration to template the appropriate values into the widget configuration.

    You can read a bit about this in the context of resetting widget selection state to default values in this section of the documentation.

    You can also search your Foundry instance for some helpful Slate tutorials - find the Foundry Training and Resources project and navigate to the Reference Examples/App Building In Slate/1. Tutorials folder to find a series of interactive Slate apps demonstrating the many patterns for using Handlebars, Functions, and other Slate components.