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

Insert current time if the same field is visible.

New Here ,
Nov 15, 2023 Nov 15, 2023

Copy link to clipboard

Copied

Hello!

I'm trying to crate a pdf form, and I have a field called  "1" that is a Text Field, and another filed called HoraI1 that is a Text Field too, but it's locked from editing and hiden if the field "1" is currently empty, and it should insert the time when and become visible when the user starts typing, but it will not hide when "1" becomes empty again. I managed to make these features, like, when I start typing, It shows the field and when I erase everything that I typed, it keeps showing, but, I can't find a way to make it insert the current time, because, if I insert a javascript to do this in the field "1", everytime that someone types anything, it changes the time to the current one, so, if it was 09:00 when the user typed something, if he changes after that, like, 09:10, the time changes too until he stops typing. Im trying to make it frozen in the first time that showed up, so, I though about doing something like, keeping the code to show the field "HoraI1" in the field "1", and insert a code into "HoraI1" to detect his own visibility and, if its visible, it will change the value of the field to the current time, so, as the field will not hide anymore, even if the user erase everything or changes the field "1", the field "HoraI1" will keep his visibility to visible, and I think that will keep the current time frozen.

There's a way to make this field detect his own visibility and if its visible, inserts the current time?


Another thing that Im afraid of, is this: The field "1" has the code to show the "HoraI1" when he is not empty, and I think that, if the user starts doing changes, every single letter erased or inserted, it will make another change to the field "HoraI1" to set the visibility to visible, so, I think that, if we put a code to detect the visibility of the "HoraI1", everytime that the "1" sends the "visible" value to the "HoraI1", it will detect that he changed to "visible" again (Even if its already visible) and changes the time to the current one again. If it really starts doing like that, please, help me to make it not happen.

TOPICS
How to , JavaScript , PDF forms

Views

163

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

correct answers 2 Correct answers

Community Expert , Nov 15, 2023 Nov 15, 2023

Use this as custom calculation script of "Horal1" field:

var f = this.getField("1").valueAsString;
var cd = new Date();
var time = cd.toLocaleTimeString();
if(f !== ""){
event.target.display = display.visible;
if(event.value == "")
event.value = time;}

Votes

Translate

Translate
Community Expert , Nov 15, 2023 Nov 15, 2023

Format the field as time with HH:MM as format.

Votes

Translate

Translate
Community Expert ,
Nov 15, 2023 Nov 15, 2023

Copy link to clipboard

Copied

Use this as custom calculation script of "Horal1" field:

var f = this.getField("1").valueAsString;
var cd = new Date();
var time = cd.toLocaleTimeString();
if(f !== ""){
event.target.display = display.visible;
if(event.value == "")
event.value = time;}

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 15, 2023 Nov 15, 2023

Copy link to clipboard

Copied

That's doing almost the job, but its coming with the seconds too, and I can't find how to prompt only Hours and Minutes, can you help me?

Another thing that I was planning to do, is to create another text-field that will calculate the time between the HoraI1 and Hora1, like this: HoraI1: 09:18 + Hora1: 10:20 = Total: 01:02.

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 15, 2023 Nov 15, 2023

Copy link to clipboard

Copied

LATEST

Format the field as time with HH:MM as format.

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