Calendar Popup Fallback Value

How do you set a fallback value of null or none for a calendar popup in SQL query binding? This is on Vision

This is an interesting question. If the date is nonsense, then it would be better to have the calendar's textfield blank, and a null value makes that happen.

Unfortunately, the closest the binding fallback value can get to being null is blank, but this results in the Unix epoch being displayed in the calendar. My first idea would be to use the propertyChange event to drive a null value into the date property any time the date changes to January 1st 1970:

if event.propertyName == 'date' and event.newValue == system.date.parse('Jan 1, 1970 00:00', 'MMM d, yyyy hh:mm'):
	event.source.date = None

...but the date change event doesn't get detected when it's driven by a SQL binding, so I'm guessing that whatever parameters are used in the supply the SQL binding will have to be used to drive the null value. Perhaps to accomplish this, the binding will have to be abandoned and the whole thing will need to be driven by scripting.

Example:

if event.propertyName == 'drivingProperty':
	query = 'SELECT dateColumn FROM dateTable WHERE ID = ?'
	queryResult = system.db.runPrepQuery(query, [event.newValue], 'myDatabase')
	if queryResult:
		event.source.date = queryResult.getValueAt(0, 0)
	else:
		event.source.date = None

Hi !
I am new to ignition and i was wondering if it was possible to set the fallback value manually.

To give more context, i am using a screen where user select a start time and stop time for a process cycle with popup calendars. The date is not important but I need to be able to calculate the cycle time in minutes.

To do so user can write in the text field next to the pop calendar. However, since the format is set to 'h:mm a' when using the tab key to exit the edition, the date reset to the 1st of JAN 1970... Which won't allow me to calculate my cycle time correctly. As shown in the picture :

Is it possible to find a way to keep the date to the current day after exiting the text field ? Also, I don't have space to make the text area bigger and to display the day directly in the textfield and I would like to make it as user friendly as possible.

Thanks in advance !

Are you using a dateDiff() function to calculate your times, so you need it to be a date object for the calculation? Or do you not need the date at all and only a time? If you are only interested in the time and the date will always be whatever day it currently is, you could use scripting in a custom property or tag to pull the current date, format it to be displayed the way you would like and use custom drop downs with a date column bound to a custom property or text fields for the time inputs and concatenate them all together in another component or property to be displayed how you would like for your calculations. You can convert the strings back to a date for datetime calculations if needed. There are many different ways to achieve what you are looking for, but it seems like the popup calendar may not be the best component for what you have in mind.

Oy! Don't do this. Keep date objects as date objects. Manipulate them as date objects. Convert to string only when UI components need to display, and then only when the component cannot natively do so.

Ah, I see I got my wires crossed somewhere while writing that. That was essentially what I was trying to say was for them to do their calculations with the date objects and then format it to a user-friendly string as needed, since they said they do not have the space to display a full date.

I thought I had read back over that post better than that before posting it but must have gotten distracted.

Thanks for catching that, my words did not match my thoughts lol.

1 Like