Initially Leave a blank field then display text conditionally based on lowest value

Community Beginner ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

I have some javascript that mostly works for me but have just one issue that should be simple. Basically I have a form set up like this:

 

 DBBDBC+DBBC+DB
Total Ranking Score30020040050

 

Suggested MethodC+DB

 

The way it works is it searches the number fields in the first table (each is named RankingScore.DBB, RankingScore.DB, etc. to put them in a group) for the one with the lowest number and then populates the name of that column using the tooltip from the same field (the tooltip has the same name as the column).

 

Here is the Javascript that I have in the Calculation for the SuggestedMethod field:

var oMinFld = null;
// This line gets all the fields in the "RankingScore" group and
// finds the one with the lowest value. It assumes all fields contain a valid value 
this.getField("RankingScore").getArray().forEach(
      function(oFld)
      {
         if(!oMinFld || (oFld.value < oMinFld.value))
              oMinFld = oFld;
      }
);
if(oMinFld)
   event.value = oMinFld.userName; // this is the tooltip
else
   event.value = "";

This works great. The problem is that each of the RankingScore fields is a calculation of data from elsewhere in the form and are initially set to calculate at 0 until the user starts entering in numbers in said other fields. 

 

The problem is that the initially the name that shows in the SuggestedMethod box automatically populates with the column with the lowest number from the left. That means that even before it starts getting calculations it is set to DBB because all values are 0 (and that is the leftmost column). I'd like the box to remain blank until the calculations make those numbers higher than 0.

 

I belive that the current else statement would work if there were no calculations in the RankingScore group. I have tried to say something like this but it doesn't work.

if(oMinFld === 0) // or < 0.1
   event.value = "";
else
   event.value = oMinFld.userName; // this is the tooltip

Any suggestions on how to get the SuggestedMethod field to show up as blank when all the fields are 0?

TOPICS
JavaScript

Views

25

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 23, 2022 Jul 23, 2022

Copy link to clipboard

Copied

LATEST

Use this:

var oMinFld = null;
this.getField("RankingScore").getArray().forEach(
function(oFld)
{
if (oFld.value > 0 && (!oMinFld || (oFld.value < oMinFld.value)))
  oMinFld = oFld;
}
);

if(oMinFld)
  event.value = oMinFld.userName; // this is the tooltip
else
  event.value = "";

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines