# Help with Toggle Switch and DateTime picker

**URL:** <https://forum.inductiveautomation.com/t/help-with-toggle-switch-and-datetime-picker/91202>\
**Category:** Ignition\
**Created:** [May 31, 2024, 3:02pm UTC](https://forum.inductiveautomation.com/t/help-with-toggle-switch-and-datetime-picker/91202 "2024-05-31T15:02:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Rocha](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@Jorge\_Rocha](https://forum.inductiveautomation.com/u/Jorge_Rocha)\
**Post date:** [May 31, 2024, 3:02pm UTC](https://forum.inductiveautomation.com/t/help-with-toggle-switch-and-datetime-picker/91202/1 "2024-05-31T15:02:39Z")

</div>

I have been asked to toggle a switch and disable the datetime picker and set the date and time to now() expecting a 1 second refresh. Now if the toggle changes I need enable the datetime picker and set it to the current date and time and let the user pick the date from that.

I´m trying to do a binding to the datetime picker Value with property binding having the state of the toggle and then adding an Expression with the following  
if({value}=false, now() , now(0))

the issue is when the toggle is true, the datime picker shows current datentime but still refresh and the user can´t pick a past date, the date and time is selected by the user but it goes back to the current time.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/9/c95afc0e03911c37a146481f62ff7dc20961d488.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 31, 2024, 3:20pm UTC](https://forum.inductiveautomation.com/t/help-with-toggle-switch-and-datetime-picker/91202/2 "2024-05-31T15:20:41Z")

</div>

It doesn't seem like a good user experience. I think you should replace the date picker with a label if the **Live** option is selected. Anyway,

- On the date picker, create `custom.dateTime` property.
- Add an expression binding,

```python
if({../tglLive.props.selected},
	now(5000), // update every 5 x.
	{this.props.value}
)

```

- On `props.enabled` add the expression binding,  
`!{../tglLive.props.selected}`

The result will be this and when you toggle Live off the previously selected date will still be there.

![Live date](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/1/b1415b84d50f7a2c991a1db637ac5ccc53caaf04.gif)

As mentioned, I would replace the picker with a label to show the value of `custom.dateTime` and enable the display of it and the datetime picker based on the toggle.

* * *

Tip: your expression  
`if({value} = false, now() , now(0))`  
can be simplified to  
`if({value}, now(0) , now())`  
Not that you want to use it anymore.

---

<div class="post-metadata">

**Author:** ![Jorge\_Rocha](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@Jorge\_Rocha](https://forum.inductiveautomation.com/u/Jorge_Rocha)\
**Post date:** [May 31, 2024, 8:51pm UTC](https://forum.inductiveautomation.com/t/help-with-toggle-switch-and-datetime-picker/91202/3 "2024-05-31T20:51:22Z")

</div>

Thank you so much, I have tested your solution and it works! I will try the label as you mentioned, I appreaciate the last tip.
