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

How to - PDF form, "after change" event handling.

Explorer ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

I have forms that perform quite complex operations and calculations based on the entered data (text fields, combo boxes, radio fields). Calling the function each time the focus is lost introduces unnecessary delays in operation, because in such a situation I perform a complicated and time-consuming analysis even though nothing has changed (and this is the case in 90% of cases when the event after the loss of focus is triggered). In fact, I need to implement a handler for the "after change" event, which is not explicitly in the field properties. What's the best way to accomplish something like this? I'm asking because I feel like I'm doing something wrong, and there's probably a simpler way to do it.

TOPICS
How to , JavaScript , PDF forms

Views

1.4K

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 ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

"In fact, I need to implement a handler for the "after change" event, which is not explicitly in the field properties."

 

Validation is available in the field properties.

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
Explorer ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

It's so simple that I'm ashamed I didn't read it myself. And all you need is:
if(event.value!=event.target.value){
"call function";
}

However, I am having a problem. The called function is based on the values given in several fields and does not distinguish (at least for now) why it was called, it is simply known that one of the input parameters has changed, so it must be calculated.
On the output of the function, after calculations, I change the values of some fields, including the input ones, and here is the problem.
I can't change the value of a field whose change caused an action to be triggered.
To better understand, let's say that I entered a non-round net price of the goods on the invoice, and as a result of the calculations, I round the price and calculate the tax and gross price, so I want to change all the fields, including those that caused the action to be triggered.

When invoking the calculation based on the script during validation, I have the new price in the event.value property so far, the previous outdated price is in the this.getField("Field").value property
After the calculations, I can't change this.getField("Field").value because an error is thrown:
InvalidSetError: Setting not possible, corrupted or unknown.
The field's value property (not event.value) is "read-only" at this point.

I guess it looks quite complicated, in other words:
How to commit the change during the validation event handling, so that inside this procedure I can refer to the field value as if it was already validated a long time ago.

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 ,
Feb 22, 2023 Feb 22, 2023

Copy link to clipboard

Copied

"When invoking the calculation based on the script during validation, I have the new price in the event.value property so far, the previous outdated price is in the this.getField("Field").value property
After the calculations, I can't change this.getField("Field").value because an error is thrown:
InvalidSetError: Setting not possible, corrupted or unknown."

 

Why want you change this value?

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
Explorer ,
Feb 22, 2023 Feb 22, 2023

Copy link to clipboard

Copied

Because this is the logic of this form, as I wrote above for calculating the price.
In each line of the form, I have fields specific to that line, i.e. quantity, net price, gross price, tax rate, net value and gross value. There are also global fields for the entire form, in which I choose, for example, the method of calculating the tax: net or gross, individually or collectively.
I wrote one rather complicated function that analyzes all this and updates the correct fields. It is invoked when any of the fields containing parameters on the basis of which calculations are made is changed. It works properly, provided ... that I don't call it from the validation handler, because it shows the error I quoted in the previous post.
Changing this function is a lot of work for me, but calling it every time the focus is lost (even when nothing has been changed) introduces unnecessary delays. Therefore, it would be ideal for me to call "commit work" as in SQL and not change anything in the function.
I'm even considering creating a hidden field for each line of the form that stores the "previous data" of the fields on that line, and when I lose focus, I just do a few simple things to see if anything has changed or not, and if I need to update the calculations. I'm sure it will work, but I know it's definitely not the most elegant solution.

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 ,
Feb 22, 2023 Feb 22, 2023

Copy link to clipboard

Copied

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
Explorer ,
Feb 22, 2023 Feb 22, 2023

Copy link to clipboard

Copied

Valuable but questions keep popping up like mushrooms after rain.
At what point does the value just entered become the valid value that I can read as value or valueAsString for the field?

I will ask directly:
I want to receive a boolean flag with the value true if the field has been changed at the focus loss handler level. How to do it?

 

Do you have a link that describes this diagram exactly? What and when is happening?

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
Explorer ,
Feb 22, 2023 Feb 22, 2023

Copy link to clipboard

Copied

I guess I answered myself.
Correct me if I'm wrong.
1. At the document level at startup, I define a global boolean variable,
2. In the script for handling field formatting, I set this variable to true, because formatting will only be called if something changes.
3. In the script that handles the loss of focus, if this flag is true, I call some function.
4. In the script that handles the loss of focus, I set the variable to false in the last line of this script, so as not to loop.

I think right?

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 ,
Feb 22, 2023 Feb 22, 2023

Copy link to clipboard

Copied

LATEST

> At what point does the value just entered become the valid value that I can read as value or valueAsString for the field?

- After the Validation event.

> I want to receive a boolean flag with the value true if the field has been changed at the focus loss handler level. How to do it?

- Use the Validation event. If the value is not changed, this event will not execute, even if the user made changes to the field, and then undid them, or if they just entered into and then exited it without making any changes at all.

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