• Cindy Chastang
    May 18, 2016 at 11:47 am #1817

    I have a table with multiple rows.   On each row there is a single select where the user will select a status.    I need to validate to ensure that all rows in the table are set to “Complete” when the user attempts to submit the coach.

    I have created a function to do the validation and can access the data in the list to check the value with no problem.   But I can’t figure out how to access the single select control on each row to setValid.

    I am using toolkit version 4.3.3 EE on BPM 8.5.7

    Here’s the javascript I’ve got so far defined in the script block of custom HTML on the coach and called from a button:

    var checklistList = page.ui.get(“checklistItemsTable”).getData();
    var checklistStatusControl = page.ui.get(“checklistItemsTable/ItemStatusSelect”);

    for (var i = 0; i < checklistList.length(); i++) {
    var status = checklistList.items[i].completeStatus
    if (status != “Complete”) {
    checklistStatusControl.setValid(false, “error msg – status must be complete”);   –> this always puts the error on the first row and only the first row…
    }
    }

    Cindy Chastang
    May 18, 2016 at 12:53 pm #1818

    As sometimes happens – I was debugging something else in my table when I saw a message in the console that led me to the solution.

    Here is code that works:

    var checklistList = page.ui.get(“checklistItemsTable”).getData();

    for (var i = 0; i < checklistList.length(); i++) {
    //debugger;
    var checklistStatusControl = page.ui.get(“checklistItemsTable/ItemStatusSelect[” + i + “]”);
    checklistStatusControl.setValid(checklistStatusControl.getData() == “Complete”, “The status of all activities must be Complete.”);
    }

    jmac
    May 18, 2016 at 1:01 pm #1819

    Was just about to post this, Same idea as you had.

    function validateTable(button)
    {
    var table = page.ui.get(“Table1”); // Access the Table

    var numRecs = table.getRecordCount(); // get the number of records
    var retVal = true; // assume good validation

    for (var i =0; i < numRecs; i++) // loop
    {
    var sel = table.ui.get(“Single_Select1[” + i + “]”); // access Single_Select for this row.
    if (sel.getSelectedItem() != “Complete” ) // check value for Complete
    {
    sel.setValid(false,”Status must be Complete”); // Set invalid
    retVal = false; // Set bad validation
    }
    else
    sel.setValid(true); // set valid
    }

    return retVal // if True button closes, if false, validation error(s) will show
    }

    lai
    March 5, 2018 at 1:11 am #5020

    Hi,

    The code above is work fine if the table only has one page, but how about if I have pages of record for a table?

    For my testing , table on screen showing page 1 records , when the code trying to get data for second page’s record, error hit :
    Cannot read property ‘getSelectedItem’ of null.

    Appreciate your input.

    Thanks.

     

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Start typing and press Enter to search