- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:25 PM
I have created a settings page using UI builder. In that page I have a toggle and if the toggle is enabled then I want to trigger a scheduled job.
How we can check whether the toggle is enabled/disabled?
Thanks
Ajay
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 07:46 AM
One way to do this is to:
1. set up a boolean state variable such as toggleState
2. Bind the checked property to your state variable
3. Update the state variable when the toggle changes
4. you can then access the state variable later such as in this script I wrote when a button is clicked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 06:30 AM
The event handlers associated with the toggle do not run in sequence, so it is possible your script runs before the state is updated.
If you want to you reference the toggle value and update state all in one script something like this:
/**
* @Param {params} params
* @Param {api} params.api
* @Param {any} params.event
* @Param {any} params.imports
* @Param {ApiHelpers} params.helpers
*/
function handler({api, event, helpers, imports}) {
if (event.payload.value) { //toggle set to true
console.log('enable job');
} else { // toggle set to true
console.log('disable job');
}
api.setState("toggleState", event.payload.value);
}
In your case you may not need the state variable at all. The purpose of the state variable original was to do record the value of the toggle for later use by the button click, but it sounds like you want to take immediate action based on the toggle being clicked