Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

field values

Avatar

Level 3

Hello,

How do I set a field to be required to be less than or equal to another field?

6 Replies

Avatar

Level 10

Hi,

We probably need more information, but if you had a NumericField1 and NumericField2 and a TextField1 that became mandatory when NumericField1 was less than NumericField2 then you could use the following JavaScript code in the calculate event of a subform containing all three fields.

 

if (NumericField1.rawValue < NumericField2.rawValue) {

    TextField1.mandatory = "error";

}

else {

    TextField1.mandatory = "disabled";

}

 

Regards

Bruce

Avatar

Level 3

Hello Bruce,

My apologies, I will provide more information.

I have a numeric field that I named line 37a

The next field, line 38 must be less than or equal to Line 37a.

I tried the following calculation script, but it did not work:

if (this.rawValue > Table8.Row37a.Line37a) {

  this.rawValue = null;

}

Thank you for your help,

Ricky

Avatar

Level 10

Hi Ricky,

I think I am still missing something.  Sounds like you need to add the following JavaScript code the validate event of Line38

this.rawValue <= Line37a.rawValue;

I assume the numeric field Line38 is under Row37a.

Regards

Bruce

Avatar

Level 3

Hi Bruce,

Still no luck,

I tried putting this code in the validate event:

{

    var nLine37a = NJ1040.Page3.Table8.Row37a.Line37a.rawValue;

    var nLine38 = NJ1040.Page3.Table15.Row38.Line38.rawValue;

   

    if (nLine38.rawValue < nLine37a.rawValue)

    {

    //we're ok

    }

    else

    {

    alert("Line 38 cannot be greater than Line 37a");

    return false;

    }

}

I only need to prevent the user from entering a value that is greater than the value entered in the previous line.

Thanks for your input,

Ricky

Avatar

Level 10

Hi Ricky,

I'm not sure why you have braces around your code, is this just a fragment of your code?  In a validate event it is the last expression that is evaluated as a true or false.  So you should just need (no return required);

var nLine37a = NJ1040.Page3.Table8.Row37a.Line37a.rawValue;

var nLine38 = NJ1040.Page3.Table15.Row38.Line38.rawValue;

  

nLine38 < nLine37a;

Note that you had .rawValue on both the first two lines as well as the condition ... it should be one or the other.  Also do you have two tables, table8 and table15?

Regards

Bruce

Avatar

Level 3

Thank you Bruce this helped a lot!

I added the following to the ValidationState event to clear the field if it fails validation:

if (this.errorText) this.rawValue=null

Thanks again,

Ricky