Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Looping thru instance manager and checking radio button selected

Avatar

Level 3

I need to loop thru my instances and toggle visible/hidden if a particular radio button in each instance is selected.

My code right now does not work but I feel I am on the right track (minus the else statement it will need to toggle on/off).

Can anyone help? thanks in advance!

var rowCount = BugGroup_f.instanceManager.count;

for (i=0; i<rowCount; i++) {


var str = xfa.resolveNode("BugGroup_f.detail3.bugInfo.BugItem.status.RadioButtonList[" + i + "]").rawValue;

    if (str.indexOf("Fixed") > -1) {
    xfa.resolveNode("BugGroup_f["+rowCount+"]").presence = "hidden"

    }
}

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Yup, though the exact logic of which are hidden or unhidded can be tweeked however you like.

That exact code will hide(or leave hidden) any row whos radio button is set for hiding. And will allow you to call it with a reset value (1) that will unhide all rows reguardless.

if you want other logic than that, it's just a question of what you put inside the for loop, and can be as complex as you like.

EDIT:

To add a script object, Right-Click on the top form in the hierarchy window, and pick "add script object."

It will make an unnamed object down below (under "variables") and you can put any code in there that you like, in the form of "functions."

then to run the code you reference the Function by name from some form event, and you're off to the races, so to speak.

View solution in original post

8 Replies

Avatar

Level 2

You might be able to use this since I've simplified it a bit from what we use.  We have a field called 'policyType' wrapped in a subform called 'subOtherInsuranceDetail'.  This subform is wrapped in a subform called 'subOtherInsuranceList'.  We need to find the number of instances of 'policyType' that contain a string 'aString'.


var otherDetailLines = subOtherInsuranceList.resolveNodes("subOtherInsuranceDetail[*]");

for (i = 0; i < otherDetailLines.length; i++)
    {
    if (otherDetailLines.item(i).resolveNode("policyType").rawValue != "aString")
            {
                otherUncompleteRows = otherUncompleteRows + 1;
            }
    }

Avatar

Former Community Member

Remember that the count is 1 based but the instances are 0 based ......so you will have to subtract 1 from the count to get the correct instance that you want.

paul

Avatar

Level 3

Ok great! My row instance is named BugGroup_f. My radio button group is 4 subforms deep within this. My updated code looks like this but is only changing which radio button is selected. It does not seem to be hiding the instances.

var otherDetailLines = xfa.resolveNodes("BugGroup_f[*]");

for (i = 0; i < otherDetailLines.length; i++)
    {
    if (otherDetailLines.item(i).resolveNode("employees.P1.BugGroup_f.detail3.bugInfo.BugItem.status.RadioButtonList").rawValue = "2")
            {
                otherDetailLines.presence = "hidden";;
            }
    }

Message was edited by: malaki - I was able to tweak something which got me closer. I changed the var

Avatar

Former Community Member

Check you're IF statement conditional there.  ; )

Additionally, I think there's a much much easier way to do the object referencing, but give me a couple minutes to type that up.

EDIT:

Let me double check what it is you are trying to do: you want one radio button in each row to be able to hide that row?

so

Row object

     L Radio button

and flipping the button turns off it's own Row object and no others?

Avatar

Level 3

Even closer now: My code is looping through and hiding the right rows but now i cannot unhide them. any help?

var otherDetailLines = xfa.resolveNodes("BugGroup_f[*]");

for (i = 0; i < otherDetailLines.length; i++)
    {
    if (otherDetailLines.item(i).resolveNode("BugGroup_f.detail3.bugInfo.BugItem.status.RadioButtonList").rawValue == "6")
            {
                otherDetailLines.item(i).presence = "hidden";
            }

     else if (otherDetailLines.item(i).resolveNode("BugGroup_f.detail3.bugInfo.BugItem.status.RadioButtonList").rawValue != "6")
            {
                otherDetailLines.item(i).presence = "visible";
          }
}

Avatar

Former Community Member

So we've got a set of Rows, each with a subitem called RadioToggle, and you want to go through and set them all, then click a separate button and hide the ones with "on" radio buttons?

function ToggleRows(reset){

     var Rows = Form.subform....BugGroup_f.all;

     var curRow;

     for (var i=0; i<Rows.length; i++){

          curRow = Rows.item(i);

          if ((curRow.RadioButton.rawValue == "WhatevermeansHidden") && !reset){

               curRow.presense = "hidden";}

          else{

               curRow.presense = "visible";}

     }

}

^ in a script object, and put

scriptObjectName.ToggleRows(reset);

in the click event of your button, and you should be golden.

If you do want them to hide the moment you click the toggle, you could put this, right?

if (xfa.event.newText == "whatevermeansoff"){

     parent....presense = "hidden";}

The .all method seems like a much easier way to handle collections of objects, and specificaly collections of instances. It also means you can do relative referencing, i.e. to create a function that will operate on all the rows of a table, without knowing which table it is operating on, so a button in each table can pass it's parent table to the function.

var GroupVariable = Object.all

for(var i=0; i < GroupVariable.length; i++)

EDIT:

add a reset value, and pass it in to your function like above (added).

make a separate button, or control, that will call the function with reset = 1.

Avatar

Level 3

Thanks for the assistance. I want to make sure we are on the same page before I attempt your solution.

Click a button which will:

1. Go through all rows and CHECK them all for a particular value in a radio button group

2. Hide/unhide the ones with that found value (depending on thwir current presence state)

PS What is a script object?

Avatar

Correct answer by
Former Community Member

Yup, though the exact logic of which are hidden or unhidded can be tweeked however you like.

That exact code will hide(or leave hidden) any row whos radio button is set for hiding. And will allow you to call it with a reset value (1) that will unhide all rows reguardless.

if you want other logic than that, it's just a question of what you put inside the for loop, and can be as complex as you like.

EDIT:

To add a script object, Right-Click on the top form in the hierarchy window, and pick "add script object."

It will make an unnamed object down below (under "variables") and you can put any code in there that you like, in the form of "functions."

then to run the code you reference the Function by name from some form event, and you're off to the races, so to speak.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----