Skip to main content
Participant
Aug 19, 2021 4:07 PM UTC
Question

How to allow various time formats into a field (HH:MM, hh:mm, HHMM or HMM) but always output HH:MM?

Is there a way to allow various time formats into a "Time" field but have the field contents display HH:MM?

Using the Format tab of the field's Properties, it seems to allow only one format, but the PDF users want more flexibility. Specifically, to input with or without a comma, but output in the field with a comma.

Thanks.

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

Participant
Aug 19, 2021 7:48 PM UTC

Thank you for your thoughts on the matter. I know that some scripting is needed. 

I've written a validation script and attached it to the "Properites >Validate" tab, which allows HH:MM, HHMM, hh:mm, or hhmm
But I can't figure out how to format the output to always be HH:MM

For this second part, I thought maybe a script in "Properites > Calculation"  or "Properites > Format" to do the following
(1) get field value
(2) strip out non digits
(3) set field to date format of HH:MM

For example
var enteredTime = getField("TimeField").value;
var numberPattern = /\d+/g;
var extractNum = enteredTime.match( numberPattern );
event.value = (util.printd("HH:MM", extractNum));

But it does not work. I am not familiar with JavaScript or Regular Expressions, so maybe I'm doing something wrong. Or maybe I'm not using the "util.printd" function properly. I'm lost.

Translate
try67
Community Expert
Community Expert
Aug 19, 2021 4:10 PM UTC

Yes, but you'll need to write a custom validation (and possibly also keystroke and format) script to do it.

Translate