Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

NumericTextBox

Avatar

Former Community Member
I have two numeric text boxes on a form. One boxes is used to enter a number and the other box shows what the total amount due is after you tab out of the first box. Is there away to refresh the second box after you enter a number but before you tab out of the first box.



Thanks Bill
5 Replies

Avatar

Former Community Member
You could try writing your code in the Change event of the first numeric text box.

This line would fetch the current value in your first numeric text box.

xfa.event.newText;

By getting this data, you can do the calculations you want.



AMAL

Forms Developer

India.

Avatar

Level 4
You have to understand that there is a series of events that occur when the user tabs out of a field. The entered data is formatted, validated, and then "Committed" (applied) to the field. It is at this point that calculations in the other fields are triggered.



The new field value does not exist before it is committed. If you were to trigger the calculation in the "Sum" field early, like in the change event, it would not work properly because the correct values are not yet there.



If the user hits the "Enter" key instead of "Tab", this same progression happens, only the focus stays on the field. I think that this is what you are looking for.



Thom Parker

WindJack Solutions


www.windjack.com

Avatar

Level 4
Hi



When talking about field validation, I have a puzzle..



I have a field and have entered a validation and script error message on the field tab. I have setup a script validation in the validate event of the field.



I would like to keep the user in the field if validation fails. I can do this by the xfa.host.setFocus( this.name );

but if I do this in the validate event, I do not have the validation and script error message on the field tab shown, as this occur when the validate event finishes and this is cut off in some way.



I could place the validation in the exit event of the field too, but that is redundant and should not be neccessary. I also wonder if a flag exist that states if the field has validate = false - is there??



Any good suggestionss/olutions are more that welcome!



Regards

Thomas Groenbaek

Jyske Bank, Denmark

Avatar

Level 4
The following validation script works for keep the focus in the field and displaying the defined error message



var bRtn = this.rawValue > 10;

if(!bRtn)

xfa.host.setFocus("form1.Pg1.NumericField1");

bRtn;



The last statement is the validate value returned to Acrobat.



Thom Parker

WindJack Solutions


www.windjack.com

Avatar

Level 4
Hi Thom



Thanks for input. Don't know why I didn't think of a bool variable.



I have made it work in the following way, which is simple and easy to use for my forms designers.

Your solution didn't solve the problem completely, as the Validation Script Message entered on Fields value tab first prompts as the users leaves the validate event. This will not happen if setFocus method executes in the validate script.



I have split the script in a validate event and en exit event with the setFocus, see code below:



----- form1.p1.num_pct_NY::validate - (JavaScript, client) -----

//ensure that input is 0-100

var bRtn = this.rawValue <= 100 && this.rawValue >= 0;

if(!bRtn) this.validate.scriptTest = "error";



----- form1.p1.num_pct_NY::exit - (JavaScript, client) -------

if(!bRtn)

xfa.host.setFocus("form1.p1.num_pct_NY");