Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Too many validations on sum boxes

Avatar

Former Community Member
I am creating a PDF form and scripting it with Javascript. In the validate event of 12 different edit controls (numeric) there are two operations happening. 1) The 12 fields are summed and the results are put into the rawValue of two other edit controls representing the total feet and inches. 2) Each field is validated to show the user if they enter a value outside of the 0 to 24 inch range. Here is the summation function.



function SumPlateHolePatterns()

{

var

totalInches = 0;



totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue1.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue2.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue3.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue4.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue5.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue6.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue7.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue8.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue9.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue10.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue11.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue12.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue13.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue14.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue15.rawValue;

totalInches += xfa.form.F.SecondPage.PlateHolePatternsValue16.rawValue;



xfa.form.F.SecondPage.HolePatternFeetTotal.rawValue = totalInches / 12;

xfa.form.F.SecondPage.HolePatternInchesTotal.rawValue = totalInches - (xfa.form.F.SecondPage.HolePatternFeetTotal.rawValue * 12);



SummingPlateHolePatterns = 0;

}



here is the validation function:



function ValidateZeroToTwentyFour(Control)

{

var

Inches = 0;



Inches = Control.rawValue;



if (Inches == null)

; //Must specify to do nothing for the else to work

else

{

if (Inches < 0 | Inches > 24)

{

xfa.host.messageBox('The value entered in Inches must be greater than 0 but may be up to 24');

Valid = false;

}

}

}



The validation works if we do not write to the total fields. As soon as we write into the total fields, and the user enters a value that causes the validation routine to show it's message box, we get roughly 12 individual message boxes for one error. If I just comment out the two lines that display the total then we get one messagebox as intended.



I have tried to use a floating text field to display it since I figured that it would not fire the validation again. I was unsuccessful getting it to display. I also tried making the validation non-reentrant by setting a global variable to 1 when I was inside the summation function. This did not work since, it appears, the entire function is completed before the reentrance happens.



What I am looking for is 2 things...

1) I want to have an error displayed when the user leaves a field when the input is incorrect.

2) I want to see the sum update when the user leaves the field too (if there is a better place to put this than the validate event, I am all ears :-)



I have been doing programming for over 20 years now. I am new to the Adobe forms scripting. I would really appreciate any help.



Brian Thomson
0 Replies