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

Select multiple rows

Avatar

Level 3

Hi,

I have a dynamic table of user accounts, and the user can select a single account from that table.  Each table row has a checkbox in the first column that the user can select, and, when selected, the index of that row is submitted to the form's java script object for further processing.  Using the index allows me to get that row's table data.  So far so good...

Now the client wants to be able to have the ability to select multiple accounts from the dynamic table. So I will need to remove the checkbox's onClick event and add a button that the user can click once all accounts have been selected.

How do I get a handle to the (one or more) checkboxes that were selected in the table rows?  Can you provide a javascript example?

Thank you,

Elaine

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Here is a view of my dynamic form...(click the image to see the whole thing)

get-selected.PNG

and the script attached to the "Get Selected" button.

// form1.purchaseOrder.detailHeader.checkSelectedBtn::click - (JavaScript, client)

var indexStr = getInstanceData(xfa.resolveNodes("detail[*].selected"));
if (indexStr.length != 0) {
    for (var i=0;i < indexStr.length; i++) {
        xfa.host.messageBox("You selected " + indexStr.substring(i,i+1));
    }
}

function getInstanceData(node) {
    var str = "";
    if (node.length != 0) {
        for (nNodeCount=0; nNodeCount < node.length; nNodeCount++) {
            // test if the checkbox is selected
            if (node.item(nNodeCount).rawValue == "1") {
                str += nNodeCount;
            }
        }
    }
    return str;
}

I substring and display the index string for demonstration purposes. The form and the sample data are attached. With any luck the virus scanner will not indefinitlely enqueue the assets.

Steve

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

Here is a view of my dynamic form...(click the image to see the whole thing)

get-selected.PNG

and the script attached to the "Get Selected" button.

// form1.purchaseOrder.detailHeader.checkSelectedBtn::click - (JavaScript, client)

var indexStr = getInstanceData(xfa.resolveNodes("detail[*].selected"));
if (indexStr.length != 0) {
    for (var i=0;i < indexStr.length; i++) {
        xfa.host.messageBox("You selected " + indexStr.substring(i,i+1));
    }
}

function getInstanceData(node) {
    var str = "";
    if (node.length != 0) {
        for (nNodeCount=0; nNodeCount < node.length; nNodeCount++) {
            // test if the checkbox is selected
            if (node.item(nNodeCount).rawValue == "1") {
                str += nNodeCount;
            }
        }
    }
    return str;
}

I substring and display the index string for demonstration purposes. The form and the sample data are attached. With any luck the virus scanner will not indefinitlely enqueue the assets.

Steve

Avatar

Level 3

Super!  Thanks Steve!  Marked as question answered ;-)  Thanks!

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] ----