Target: Create a variable which has the default date as value. Then use this value as default for date picker component in ToolJet app.
Steps:
- Add new query of type “Run JavaScript code”
- In the code section paste the following code:
const currentDate = new Date();
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2,'0'); // Months are 0-indexed
const day = String(currentDate.getDate()).padStart(2, '0');
today = `${year}-${month}-${day}`;
actions.setVariable('dt', today);
return actions.getVariable('dt'); - Below the code make sure to switch ON in Settings “Run this query on application load?”
- Now you can use the created value in the variable “dt” in any Date picker component by simply putting the following text in “Default value” property: “
{{variables.dt}}
“