Expand my Community achievements bar.

SOLVED

Validate Numeric Field - Can be 10, 20, or 30

Avatar

Level 3

I'm using LiveCycle Designer ES (Version 8.2).

I have a numeric field that can contain a 10, 20, or 30. It can also be empty and I guess, a zero would be okay too.

How could I accomplish this, given I'm a newbie here?

Thank you for the feedback.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If your input is limited to just 10, 20 or 30, then you could use a dropdown list instead of a numeric field.

A dropdown list is good when you want to ensure that the user only inputs pre-defined values and in set formats/patterns.

Set up the dropdown list items in the Object panel and untick "Allow cistom entry". Then go to the Binding panel and tick the "specify values" box. Assign a value of 10 to "10", etc.

You will be able to refer to the rawValue of the dropdown in subsequent script, just as you would with a numeric field.

If you want to go with the numeric field, you could set up a Javascript in its exit event:

if (this.rawValue == 10 || this.rawValue == 20 || this.rawValue == 30)
{
    // do nothing
}
else
{
     app.alert("Invalid data entry: you must enter either 10, 20 or 30");
     this.rawValue = null;
}

Good luck,

Niall

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

If your input is limited to just 10, 20 or 30, then you could use a dropdown list instead of a numeric field.

A dropdown list is good when you want to ensure that the user only inputs pre-defined values and in set formats/patterns.

Set up the dropdown list items in the Object panel and untick "Allow cistom entry". Then go to the Binding panel and tick the "specify values" box. Assign a value of 10 to "10", etc.

You will be able to refer to the rawValue of the dropdown in subsequent script, just as you would with a numeric field.

If you want to go with the numeric field, you could set up a Javascript in its exit event:

if (this.rawValue == 10 || this.rawValue == 20 || this.rawValue == 30)
{
    // do nothing
}
else
{
     app.alert("Invalid data entry: you must enter either 10, 20 or 30");
     this.rawValue = null;
}

Good luck,

Niall

Avatar

Level 3

Thank you Niall -- that worked. That is, I simply used the on-exit routine that you provided.

Let me ask you this.... You said that I could use a dropdown list and I understand that AND I want to try it. However, I'm not sure how to refer-to or get access to the rawValue afterwards.

Right now I have a total field called CalcFieldSum and I simply have the following sum function in it.

Sum(xfa.resolveNode("EntryForm.Page08-EntryFees.CalcField1")

,xfa.resolveNode("EntryForm.Page08-EntryFees.CalcField2"),

xfa.resolveNode("EntryForm.Page08-EntryFees.CalcField3") )

What would I have to do to add the three numbers in the CalcFieldSum?

Thank you for your help....

Avatar

Level 10

Hi,

Firstly you are using full resolved references in your script. All of your objects are on the same page (even if they were on different pages) your script can be simplified.

Using FormCalc the script in the calculation event of CalcFieldSum would be:

CalcField1 + CalcField2 + CalcField3

Using Javascript it would look like:

this.rawValue = CalcField1.rawValue + CalcField2.rawValue + CalcField3.rawValue;

If you want to use dropdown lists, there some simple steps.

  • drag the dropdown into the form and name (CalcList1);
  • Add a null, 10, 20 and 30 to the list in the Object panel;
  • Specify the values for each of the choices in the Binding panel.

Then when you reference the dropdown lists in other objects, the script will use the specified values. For example the FormCalc in the calculate event of a CalcListSum numeric field would be:

CalcList1 + CalcList2 + CalcList3

Hope that helps,

Niall

Avatar

Level 3

Because I'm a newbie, I did not realize that I did not have to use "fully resolved reference." Thanks for that.

A also understand now how the "this.rawValue reference works. Awsome!

With this minimal information, there is MUCH I can do to enhance my form.

Great help -- thank you.