• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

formatting time field HMM to H:MM

New Here ,
Nov 02, 2019 Nov 02, 2019

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

741

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2019 Nov 02, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2019 Nov 02, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 03, 2019 Nov 03, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 04, 2019 Nov 04, 2019

Copy link to clipboard

Copied

I'm a beginner in scripting. I only partially understand this script. But it works perfectly! I see that it is necessary to limit the input to real time possibilities (0-24 and 0-59). Can you advise on this too?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2019 Nov 04, 2019

Copy link to clipboard

Copied

The keystroke script can accept or reject user input by returning true/false to event.rc.

This is easy for general, single key, filtering. but if you want to match a specific input it gets more complex.

Here's a script that puts the complete input together and decides if it is acceptable.

 

if(event.willCommit)
{
... conversion script...
}
else
{ // keystroke script
if(event.change.length > 0) { // Test only non-empty inputs, Empty input is accepted var nChars = event.selEnd - event.selStart; var aFull = event.value.split(""); aFull.splice(event.selStart, nChars, event.change); var strFull = aFull.join("");
event.rc = /(\d{1,2})[\,\.]?(\d{2})/.test(strFull);
}
}

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 27, 2023 Jul 27, 2023

Copy link to clipboard

Copied

LATEST

I am trying to replace H:MM format with HH:MM or replacing H format with HH:MM format.

The script is interesting but i have a problem with excuting it.

how can i edit it to work with what i need.

Exampel: when i enter 9:00 it should be converted to 09:00

and when i enter only 9 it should converted it to 09:00

 

Many thanks in advance

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines