Skip to main content
Piotr Smolen
Inspiring
February 21, 2023
Question

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

  • February 21, 2023
  • 2 replies
  • 2351 views

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.

This topic has been closed for replies.

2 replies

JR Boulay
Community Expert
Community Expert
February 22, 2023
Piotr Smolen
Inspiring
February 22, 2023

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?

Piotr Smolen
Inspiring
February 22, 2023

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?

Bernd Alheit
Community Expert
Community Expert
February 21, 2023

"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.

Piotr Smolen
Inspiring
February 22, 2023

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.

Bernd Alheit
Community Expert
Community Expert
February 22, 2023

"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?