How to clear Date-Time Picker after each time it is used?

hi all
I have been trying to reset the date time picker to default value after every use. I have set an expression to bind to enable tag of the "search product code " button . so that the button is only activated when it has a proper date and a tank count. So I have been trying to reset it to default. Can anyone help me with the script to make the date to a default value like null.


What is your binding on the value?

Use a script on your submit button and add a line at the end to set the value to None (Python's null) after the script is done.

1 Like

Agreed - a binding is not the way to go about this. At whatever point you deem the currently selected value of the picker to no longer be valid, you should just set the value of that picker to be None.

# this code lives in the onActionPerformed Event of the Submit button and assumes 
# that clicking the Submit button should also invalidate the picker, AND that the Submit button
# and picker are sibling components (same parent container)
self.getSibling("DateTimePicker").props.value = None
1 Like

I want the value of the date time picker to be stored in a memory tag , the binding is to a memory tag .
But if you are using a confirm dialog box when u click on submit button. Can we use the null script on the yes button??

There seems to be a disconnect here. Bindings should be used when you want something to always be synchronized with some other value. So if you bind your DateTime Picker (DTP) to a Tag value, you're essentially saying you want the DTP to always reflect the value of the Tag. If you bi-directionally bind the DTP to the Tag, you're saying you want the DTP to reflect the Tag value AND UPDATE the Tag value when a user selects a different value.


You're also claiming you want the DTP to be cleared when a user "invalidates" the selected value by some beginning or completing some sequence of events. THIS seems more like a job for a change script in conjunction with logic to reset the DTP.

What I suggest is you provide a change script for the DTP:

# This will only write to the Tag when the value of the DTP is not None
if currentValue and currentValue.value is not None:

Then, in your event sequence when you want to reset the value in the DTP, you can either do so via direct reference (previous example in a different post above), or - if the DTP is not a relative of the component being interacted with in the sequence - you can make use of Message Handling in Perspective.

Message "broadcast"/invocation:

# code to invoke on button press
system.perspective.sendMessage(messageType="ResetDTP", scope="page")

Mesasge listener (right-click DTP, select "Configure Scripts", double-click "Add handler...", supply a name of ResetDTP)

Within script of handler:

self.props.value = None

One additional note:
All of this logic seems to be based on the value of a singular tag, but as you could potentially have multiple people using this process, it's likely you'll have users writing over each other to the tag because Tags are Gateway-scoped; you should consider moving away from suing a tag for this value in the first place unless you're comfortable with inter-session contention for reads/writes.

It looks like you may be using a Require Confirm one-shot button. Is this the case?

Actually, The date time picker is used to generate a barcode for the tanks being led into the furnace through a conveyor. The date the tank was manufactured is the first 8 characters of the barcode string. The operator at the conveyor will be using this view to generate any barcodes that are missing. Hence do you think the inter-session read/ write could affect the working?

No, it is just an another view I created for a confirm dialog box, because the one shot button can only be reset by external mechanism.

In that case (assuming this is a general confirmation popup), you could use scripts as inputs to this popup and an output from the popup, dependent on if Yes or No is selected.

Use a custom tag on the view to hold the output from the popup and use an on-change script to reset your DTP value to None. Something along those lines.

It's difficult to say what exactly is going to work unless I try it for myself, but that would be my first thought.

the value from the DTP cannot be set to bi-directional when we are adding a change script to the DTP, I want the user to select the date and then it should update the tag. Also, can we set the date to todays date i,e. the current date to be set as the value of the DTP when the operator is using the view. So that it would be easier for the operator if he wants to generate a barcode of that date.

To do this us an onStartup script on root container of the view.

Still not working

This is how I would do it.

  1. Create confirmation popup. Output from pop is true or false based on Yes or No reply. You'll have to message from the popup view to the calling view because popups have no way to reference outputs back to the view that called them (post) You don't have to use message if you're okay with using the Confirm Dialog as an embedded view and toggle visibility, instead of using it as a popup.

  2. Add your submit button with a call to the confirm popup.

  3. Add a message handler to the view's root container to receive the confirm message, write the tag, and reset the DTP.

def onMessageReceived(self, payload):
	# implement your handler here
	if payload['confirm']:
		date_to_write = self.getChild("DateTimePicker").props.value
		if date_to_write is not None:
		self.getChild("DateTimePicker").props.value = None
  1. Add an onStartup script to the root container to set confirm to false and DTP to today's date. (this doesn't seem to work all the time, so maybe just provide another button to set to today instead of doing it on startup.)

Any luck?
I used part of your example on another solution:

Still not working.

Let's figure out exactly what isn't working.

Start by adding a simple "clear" button directly on the view with the DTP and use a script to set the DTP value to None (null). Does the DTP value go back to the default (blank)?

the button's onActionPerformed script should be:

def runAction(self, event):
	self.getSibling("DateTimePicker").props.value = None

Your DTP value should not be bound to anything, as you have shown in the first screenshot in your post.