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

Can I use event.change and event.changEx with date pickers?

Community Expert ,
Jun 10, 2020 Jun 10, 2020

Copy link to clipboard

Copied

I have a date field in my PDF that is using a custom calculated script to get the date value from another date field.

 

I want to be able to have the option to  manually change the date in that field using its own date picker. 

 

The problem I have is that my current script partially works but it looses the focus and reverts to the custom calculated value when I continue to work with other fields.

 

This is the script that I 'm using: 

 

 

//event.target is the current date field I want to execute this script

var a = event.target;

if (getField("myOtherDateField") !="") {
   var s = a.value = this.getField("myOtherDateField").value;
   var d = util.scand("mmmm, d yyyy", s);
   d.setDate(d.getDate()+0);  
   event.value = util.printd("mmmm, d yyyy", d);

} else {
if (a.value = event.changeEx) {
a.value = event.change;
 }
}

 

 

In the code above I know there is a lot wrong. I understand that event.change and changeEx is normally used with dropdown menus and text fields.

 

Is there a way to achieve this with date pickers?

 

It seems like it can work out, but like I indicated it looses the focus and reverts to the  calculated value if I click and hit enter on any other field.

 

I would like to give my users the ability to manually change the date in that field after it has been populated with the value of the other  date field.

 

Thank you in advance.

TOPICS
Acrobat SDK and JavaScript

Views

982

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 , Jun 11, 2020 Jun 11, 2020

I would do it differently. Chang the code to only update the field's value automatically if the source of the event (event.source) is the other date field. Otherwise, it will not change it and the user could update the value manually.

Votes

Translate

Translate
Community Expert , Jun 11, 2020 Jun 11, 2020

The SDK doesn't deal with scripting techniques, it just provides the basic documentation of the various objects.

You can do it like this:

 

if (event.souce && event.source.name=="myOtherDateField") {

// place calculation code here

}

Votes

Translate

Translate
Community Expert ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

I would do it differently. Chang the code to only update the field's value automatically if the source of the event (event.source) is the other date field. Otherwise, it will not change it and the user could update the value manually.

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 ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

Thanks for your usual quick replies.

 

I am using as reference the SDK documentation.

 

There is little to nothing mentioned  in the references I'm using about how to implement event.source to update another field automatically.

 

Do I have to declare a function, or set a variable with function using something like  an updateto method?

 

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 ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

The SDK doesn't deal with scripting techniques, it just provides the basic documentation of the various objects.

You can do it like this:

 

if (event.souce && event.source.name=="myOtherDateField") {

// place calculation code here

}

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 ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

LATEST

Great!  That did it.

 

This is how it looks:

 

if (event.source && event.source.name =="myOtherDateField") {
   var s = this.getField("myOtherDateField").value;
   var d = util.scand("mmmm, d yyyy", s);
   d.setDate(d.getDate());  
   event.value = util.printd("mmmm, d yyyy", d);
} 

 

 

I appreciate your continued support.

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