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

How would you set up a variable date field that shows the current date, but then locks upon saving the form?

New Here ,
Apr 12, 2017 Apr 12, 2017

I am trying to set up a disclosure statement that displays the current date when it first displays within an app. Once a customer were to save the form, I need that date to lock to that particular date and no longer update. 

TOPICS
Acrobat SDK and JavaScript , Windows
4.4K
Translate
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 1 Correct answer

Community Expert , Apr 13, 2017 Apr 13, 2017

Right... you'd add a document level script that runs each time the file is opened but a conditional statement first checks if the date field has a value set the date only when that's not the case. The field would already be readonly. Something like...

var dateField = this.getField("date");

if (dateField.value == "") {

    dateField.value = util.printd("mmmm dd, yyyy", new Date());

}

If you reset the form before distribution, the date field is blank. It gets filled when the file is opened and assumi

...
Translate
LEGEND ,
Apr 12, 2017 Apr 12, 2017

There's a conceptual problem...won't it lock when YOU save it?

Translate
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 ,
Apr 12, 2017 Apr 12, 2017

You can get around that by disabling JS before saving the file on your end...

Translate
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 ,
Apr 12, 2017 Apr 12, 2017

Another problem is that you can't force someone to save the file they opened, so the date will not become a part of it until they do.

They can just download the file, open it, and then close it without saving over and over.

Translate
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
Participant ,
Jun 03, 2023 Jun 03, 2023

In a pdf file we have multiple date formatted fields, For validation if I want to update the current date only for the field which has been set in date format. I tried the below script however all the fields are populating the current date, below is the script which I am using, any solution much appreciated

for (var i = 0; i < this.numFields; i++) {

var f = this.getField(this.getNthFieldName(i));

{

if (f.type == "date");{

f.value = util.printd("mm/dd/yyyy", new Date());}

}

}

Translate
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 ,
Jun 03, 2023 Jun 03, 2023

Use this.

var f = this.getField("Put field name here");

f.value = util.printd("mm/dd/yyyy", new Date());

 

Replace orange text with field name of which you wish to change date.

Translate
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
Participant ,
Jun 03, 2023 Jun 03, 2023

Hi Nesa,

Thank you for your suggestion, however in a document we have multiple fields also we have 20 to 30 date field like DOB, Date of employed .... I want to validate the form fields which is set as date format.

for consistency and any errors.

 

Translate
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 ,
Jun 03, 2023 Jun 03, 2023

Sorry, I don't understand exactly what you ask for.

You want to validate if the value of a field is in correct date format?

Translate
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
Participant ,
Jun 03, 2023 Jun 03, 2023

No Problem Nesa, I am working on pdf forms which helps disabled people to fill out  forms. I have to validate the fields used in a pdf forms. so I am trying to validate the fields which is set as date format , that should only accept the date. 

Translate
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
Participant ,
Jun 03, 2023 Jun 03, 2023

if (f.type == "date"); hope this will help 

Translate
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 ,
Jun 03, 2023 Jun 03, 2023

I don't believe you can validate a field by the type of format it is set to.

'type' property refer to what type of field it is (text, combobox, checkbox...etc.) if you used 'date field' tool it's just regular 'text field' formatted to date format.

You can validate it by field name, type or if it's filled, you can validate its value, or if it's empty.

What you try to do with validation?

 

Translate
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
Participant ,
Jun 04, 2023 Jun 04, 2023

Hi Nesa, I have to validate the fileds are correctly set in date format. 

Translate
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 ,
Jun 03, 2023 Jun 03, 2023
quote

if (f.type == "date"); hope this will help 


By @Magendravarad28403894r8lu

 

It won't. There's no field type called "date". They are just text fields with a specific Format/Keystroke script attached to them. There's no way to detect that using a script.

Translate
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
Participant ,
Jun 04, 2023 Jun 04, 2023

Thanks for the information Try67. do we have any work around for the validation.

Translate
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 ,
Jun 04, 2023 Jun 04, 2023

I'm still not sure what you try to validate, if you set the format of the field as date mm/dd/yyyy only that format can be entered into a field, any other value will not be accepted.

Translate
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
Participant ,
Jun 04, 2023 Jun 04, 2023

Nesa, I am working on the forms designing team and I have to make sure all the fields are set as per the Field requirements example DOB date format, and I have to validate the fields are set as per requirement  and to  check I have to type or select date for each field so I just want to use a javascript which will ease my work.

Below also a method I tried but still no luck. it changes all the field in the doucment 

 

for (var i = 0; i < this.numFields; i++) {
var A = this.getField(this.getNthFieldName(i));
var cFormat = "mm/dd/yyyy";
{
{
if(A.Format=("Format", "AFDate_FormatEx(\""+cFormat+"\")"));
if(A.Keystroke=("Keystroke", "AFDate_KeystrokeEx(\""+cFormat+"\")"));
{
A.value = util.printd("mm/dd/yyyy", new Date());
}
}
}
}

Translate
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 ,
Jun 05, 2023 Jun 05, 2023

To compare values use ==, not only one =.

Translate
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
Participant ,
Jun 05, 2023 Jun 05, 2023

Thanks Bernd, However it is still populating the date in all the fillable text fields. 

for (var i = 0; i < this.numFields; i++) {
var A = this.getField(this.getNthFieldName(i));
var cFormat = "mm/dd/yyyy";
{
{
if(A.Format==("Format", "AFDate_FormatEx(\""+cFormat+"\")"));
if(A.Keystroke==("Keystroke", "AFDate_KeystrokeEx(\""+cFormat+"\")"));
{
A.value = util.printd("mm/dd/yyyy", new Date());
}
}
}
}

Translate
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 ,
Jun 06, 2023 Jun 06, 2023

Remove the ; at the end of the if lines.

Translate
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
Participant ,
Jun 06, 2023 Jun 06, 2023

Bernd, nothing happened post removing ; 

Translate
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 ,
Jun 06, 2023 Jun 06, 2023

Fields don't have a Format or Keystroke properties. This is not going to work.

Translate
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
Participant ,
Jun 06, 2023 Jun 06, 2023

Hi Try67, Is there any workaround for this. 

Translate
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 ,
Jun 06, 2023 Jun 06, 2023

Not really. I don't quite follow what you're trying to achieve with all of this, if I'm honest.

The solution to your original question is very simple and was already given in this thread.

Translate
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
Participant ,
Jun 06, 2023 Jun 06, 2023
LATEST

Thanks for the help Try67 

Translate
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 ,
Apr 12, 2017 Apr 12, 2017

No need to disable JavaScript either, can just have the code only set the display property when the field has a value other than the default. Then when you are ready to distribute, you just reset the form before saving normally.

Translate
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