Expand my Community achievements bar.

Problem in date field

Avatar

Level 9

Hello All,

I have a form which has several date fields.I want to autopopulate these dates to the current date unless and until the user changes it. For ex: We have a DateField 1: When the form opens it shows today's date. If the user does not change this date and if the form is again opened 2 days after,then it shows today's date instead of showing the date which is 2 days after.

Thanks.

Bibhu.

12 Replies

Avatar

Level 9

Hello All,

Just a change to the above question,can the above concept applied to textfields as well instead of date fields ?

Thanks.

Bibhu.

Avatar

Level 9

Hi,

Bascically what I want here is : The user enter some values to other fields and does not change these date fields which are populated to current date and the user saves the form. So if the user opens the form after 2 days then the date fields show the previous days(2 days before). Any body could help me in this , I am really in a hurry.

Thanks.

Bibhu.

Avatar

Level 10

Hi Bibhu,

There are two problems trying to implement this:

  • Preventing the script that calculates the current date, from firing when the form is reopened. This script is probably in the docReady event of the current date field.
  • If the form is reopened and the user enters with the field that has the script to set the form data input date then this script will fire again, changing the date.

I think your best option is to have two readOnly date fields, currentDate (visible initially) and dataInputDate (hidden). These fields would be directly aligned one on top of the other.

Then in the field that you select as triggering the setting of the date that makes when the user input data you would hide the currentDate and show the dataInputDate. Example in the exit event

if (this.rawValue !== null)

{

     currentDate.presence = "hidden";

     dataInputDate.presence = "visible";

     //... set the date for the dataInputDate

}

else

{

     currentDate.presence = "visible";

     dataInputDate.presence = "hidden";

     dataInputDate.rawValue = null;

}

Make sure the preserve script changes is ticked in the File > Form Properties > Defaults tab.

As I say, if this field is re-entered and exited again at any stage then the script will re-fire and change the date.

Hope that helps,

Niall

Avatar

Level 9

Hello Niall,

Thanks for the help. But to be honest I am really confused here.In which event for which field I have to write the script. Lets say the nale of the date field is "IncludeDate". When a form is opened it should show the current date.But as we can see this field will always contain the value of the current date. I am scratching my head. Could you please post a sample form. I know I am bugging you a lot. But I have no choice.

Thanks.

Bibhu.

Avatar

Level 9

Hello Niall,

This script is not working. I did not make any change to the current date and  saved it.After that I changed my system's date and reopened the form again.But instead of shoing the previous date it's showing the system's changed date.

Thanks.

Bibhu.

Avatar

Level 10

Sample here: https://acrobat.com/#d=Q6-4mqQtDIcOgmIGu9*KBw

I haven't tested changing system date. Both the current date and data inputted date get there values from the system date BUT due to different events. The current date is set by the docReady event, whereas the data inputted date gets its value on exit of the name field.

Niall

Avatar

Level 9

Hello Niall,

Thanks for the form. . But my real purpose is not satisfied here. I am just scratching my head.

Thanks.

Bibhu.

Avatar

Level 9

Hello Niall,

Is it possible to store the date in a text field so that when the form is ready even if the date changes the text field will show the previous value.

Thanks.

Bibhu

Avatar

Level 10

I don't think so, as what ever script pushes the date value into the textfield in the first place will fire again under the same event.

For example if you have the script in the exit event of a field, which sets the date and pushes it to a textfield. Then everytime the user exits that field, the date will be set again as per the system clock and pushed to the textfield.

The only other example I have is where the fields that are changed are tracked by addItem() to a listbox:

https://acrobat.com/#d=06u-J6N34PQdaD25ZCPrSA

Hopefully that will give you some ideas,

Niall

Avatar

Level 9

Hello Niall,

Thanks for the link.What I am thinking is I will check the value of the DateField on "docReady" event.I mean :

if(this.rawValue != null)

{

   this.rawValue = Num2Date(Date()."YYYY-MM-DD");

}

else

{

   this.rawValue = this.rawValue;

}

Will this work ?

Thanks.

Bibhu

Avatar

Level 9

Hello Niall,

It worked. Wohooo . But I am stuck with that fonit issue. Could you please help me out ?

Thanks.

Bibhu.