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.
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
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.
# code to invoke on button press
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.
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?
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.
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.
Add your submit button with a call to the confirm popup.
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
date_to_write = self.getChild("DateTimePicker").props.value
if date_to_write is not None:
self.getChild("DateTimePicker").props.value = None
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.)