Expand my Community achievements bar.

More Scripting Help Please

Avatar

Level 2

I am working on an Adobe LiveCycle Designer form (8 pages).

Each page requires the reader to enter in points (some pages have a max of 5 Points, some have a max of 10).  In the text field that I used I want to make sure that the end user does not enter an incorrect number.  If there is a maximum of 5 points I don't want them to enter anything other than 0, 1, 2, 3, 4, or 5.  The same holds true for those pages with max points of 10 (nothing over 10).

My text fields are named TextField1, TextField2, TextField3, TextField4, TextField5, TextField6, TextField7, TextField8.

Thank you in advance.

4 Replies

Avatar

Former Community Member

If I understand your question correctly, a TextField is used to capture an integer.

In the first case you want to enforce an integer between 0 and 5.

First, set the max length of TextField1 to 1.

Second, on the exit event of TextField1 add the following JavaScript.

---------------------------------------------------------------------------------------------------

# form1.page1.subform1.TextField1::exit - (JavaScript, client)

var regExp = /\d/;

if (regExp.test(this.rawValue)) {

     if (this.rawValue > 5) {

          xfa.host.messageBox("A value less than 6 is required.");

     }

}

else {

     xfa.host.messageBox("A numeric value (0-9) is required.");

}

---------------------------------------------------------------------------------------------------
The script forces a numeric value and requests a value less than 6. You can use this script as model for all use cases.
Steve

Avatar

Level 2

Thank you for your response!  :-)

It's kind of working but not 100% working.  In the text field that needs to be locked down to 0-5 it's letting me enter 0-9...it's not locking me down to 0-5.

If attached the PDF of what I'm working on.

Thank you sooooo much!  :-)

Avatar

Former Community Member

Having seen the form you should use numeric field's rather than text field's. Numeric field's eliminate the ability to enter non-numeric characters automatically, reducing the editting burden. For the 0-5 use case the JavaScript on the exit event becomes much simpler.

if (this.rawValue > 5) {

     xfa.host.messageBox("A value less than 6 is required.");

     xfa.host.setFocus(form1.page1.Subform1.NumericField1);

}

I added the setFocus method to show you how to put the cursor back into the field in error. PLEASE REVIEW HOW THIS METHOD IMPACTS FORM USE. If you are not careful with the setFocus, it is easy to leave a user with no choice but to close the form. I think in your case the user has to enter a value.

Additionally, for demonstration purposes, I added a FormCalc script to populate the current date with the current date.

See the ready:layout event on your date field for

$.rawValue = Concat(Num2Date(Date(), "MM/DD/YYYY"))

Steve

Avatar

Level 2

Thanks! This is AWESOME and is working great!

I'm almost done!!! Just need to figure out a few more things!!!

THANK YOU!!!

Ms. Shayne R. Ortmeier

Professional Assistant

Curriculum, Instruction & Innovation Team

Department of Education

301 Centennial Mall South, 6th Floor

Lincoln, NE 68509

Direct Line: 402.471.0511

Fax: 402.471.0117

Signature Strengths

  • Restorative * Significance * Context * Responsibility * Focus *