Skip to main content
Known Participant
Nov 2, 2019 5:01 PM UTC
Question

formatting time field HMM to H:MM

How to format text field for time so input could be  H.MM or H,MM or HMM and output was always H:MM? User to be able to enter the time in any of these formats, but always appears as H:MM in the text field.

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

6 replies

Thom Parker
Community Expert
Community Expert
Nov 2, 2019 5:55 PM UTC

Do you have the ability to edit this form?

 

The time format was set by the form creator. If you want to change it. You have to change the field formatting. 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
Nov 2, 2019 8:29 PM UTC

I am the creator of the form. I want the user to enter, for example, 8.30 or 8,30 or 830 in the time field, and have javascript edit it at 8:30.

Translate
Thom Parker
Community Expert
Community Expert
Nov 3, 2019 6:29 PM UTC

So you want the field value to be entered in a variety of formats, and then converted to a standard fomat after entry? 

 

This is possible, but you'll need to write a set of custom scripts. 

1. Restricting entry to a specific set of format. This has to be done as a non-commit custom keystroke script.

2. Converting entered data into a standard format. This could be done as a will-commit custom keystroke or a validation script.

 

The 2nd part is easier. The way to do this coversion is to use a regular expression to recognize the front and end parts of the entered data and then insert the  ":".

Heres a script that will perform the conversion.

if(event.willCommit)

{

    event.value = event.value.toString().replace(/(\d{1,2})[\,\.]?(\d{2})/,"$1:$2");

}

 

The first part gets more complicated. Do you know anyting about scripting?

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often