Skip to main content
Known Participant
November 2, 2019
Question

formatting time field HMM to H:MM

  • November 2, 2019
  • 1 reply
  • 1367 views

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 has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
November 2, 2019

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. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
November 2, 2019

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.

Thom Parker
Community Expert
Community Expert
November 3, 2019

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?

 

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