Copy link to clipboard
Copied
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.
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
...Copy link to clipboard
Copied
There's a conceptual problem...won't it lock when YOU save it?
Copy link to clipboard
Copied
You can get around that by disabling JS before saving the file on your end...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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());}
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
if (f.type == "date"); hope this will help
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Hi Nesa, I have to validate the fileds are correctly set in date format.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks for the information Try67. do we have any work around for the validation.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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());
}
}
}
}
Copy link to clipboard
Copied
To compare values use ==, not only one =.
Copy link to clipboard
Copied
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());
}
}
}
}
Copy link to clipboard
Copied
Remove the ; at the end of the if lines.
Copy link to clipboard
Copied
Bernd, nothing happened post removing ;
Copy link to clipboard
Copied
Fields don't have a Format or Keystroke properties. This is not going to work.
Copy link to clipboard
Copied
Hi Try67, Is there any workaround for this.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks for the help Try67
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now