Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Onchange refresh does not work for pyRadioButtonSelectable

SA-12441

Summary



After application upgrade to Pega 7.1.6, while selecting radiobutton (pyRadioButtonSelectable), onchange refresh action does not work. OnChange event to perform" Refresh this section " action is set and then a call is made to invoke an activity execution as part of it.
Nothing gets recorded in the tracer onclick of radio button. 


Error Messages



Not Applicable

Steps to Reproduce



1. Create a repeat grid. 
2. Configure the source of Repeat grid as a property. 
3. Set one of the columns as a radio button and make it editable. 
4. Onclick of the radio button, do section refresh. 
5. Save and run the flow. 


Root Cause



The root cause of this problem is that an onclick event canot be configured on the radiobuttons which is placed in the grid as onclick event and functionality is hardcoded  (to select only one radio button in the grid) in the radio buttons control.

Resolution



This issue is resolved through the following local-change :

1. Create a non-auto generated radio button using the following code in the application:

<pega:when test='param.ReadOnlySmartInfo != "" || param.ReadWriteSmartInfo != ""'>
    <pega:include name="StartSmartField" />
</pega:when>

<pega:choose>
<pega:when java='<%= !tools.getParamValue("Direction").equals("") %>'>
 <pega:save name="strDirection" value="<%= tools.getParamValue("Direction") %>"/>
</pega:when>
<pega:otherwise>
 <pega:save name="strDirection" value="Vertical"/>
</pega:otherwise>
</pega:choose>

<pega:choose>
<pega:when java='<%= !tools.getParamValue("NumItemsBeforeWrap").equals("") %>'>
 <pega:save name="strNumItemsBeforeWrap" value="<%= tools.getParamValue("NumItemsBeforeWrap") %>"/>
</pega:when>
<pega:otherwise>
 <pega:save name="strNumItemsBeforeWrap" value="3"/>
</pega:otherwise>
</pega:choose>


<pega:save name="strPropName" ref="$THIS-DEFINITION(pyPropertyName)" />
<pega:save name="strClassName" ref="$THIS-DEFINITION(pyClassName)" />
<pega:save name="strRefName" ref="$this-name" />
<pega:save name="strValue" ref="$this-value" />
<%boolean isUsedForSingleSelect=false;%>
<pega:when java="<%= tools.getSaveValue("isGrid").equalsIgnoreCase("true")%>">
    <%
    String[] tableEditInfo = tools.getDictionary().getTableEditInfo(tools.getSaveValue("strClassName"),tools.getSaveValue("strPropName"));
    if (tableEditInfo != null)
    {
            String strTableEditMode = tableEditInfo[tools.getDictionary().TABLEEDITINFO_INDEX_TABLEOPTION];
        if (strTableEditMode !=null && strTableEditMode.equalsIgnoreCase(""))
            isUsedForSingleSelect= true;
    }
    %>
</pega:when>

<pega:choose>
<pega:when java="<%= isUsedForSingleSelect && tools.getSaveValue("isGrid").equalsIgnoreCase("true")%>">
    <%
    String output = tools.getSaveValue("strRefName").replaceAll("[\\d]" , "");
    %>
    <pega:include name="Messages"/>
    <input type="hidden" name="<p:r n='$this-name'/>" value="false"/>
    <input   type=radio name="<p:r n='$this-name'/>"
    onclick="test(event);Grids.getActiveGrid(event).setOtherRadioToFalse(this, event );"  value="true"
    <pega:when test='$this-value=="true"'> checked="true" id = "<%=output%>" </pega:when> />
</pega:when>
<pega:otherwise>
<pega:include name="Messages"/>

<pega:choose>
<pega:when test="$mode-input">

<%
String strReferenceName = tools.getSaveValue("strRefName");
String strPropName = tools.getSaveValue("strPropName");
String strValue = tools.getSaveValue("strValue");
boolean isHorizontal=tools.getSaveValue("strDirection").equals("Horizontal");
int iNumItemsBeforeWrap = 3;
try{
    iNumItemsBeforeWrap=Integer.parseInt(tools.getSaveValue("strNumItemsBeforeWrap"));
}
catch(Exception e){
}

String strPropertyName = tools.getActive().getName();
String strClassName = tools.getDictionary().fromDefinition(tools.getActive(), "pyClassName");
tools.putParamValue("propertyName", strPropertyName);
tools.putParamValue("className", strClassName);
tools.putParamValue("smartPromptMode", "true");
tools.putParamValue("showResults", "no");
tools.putParamValue("outputPageName", "");

HashStringMap params = new HashStringMap();
params.putString("pyClassName", "Rule-Obj-Property");
params.putString("pyActivityName", "getValidValues");
try{
    tools.doActivity(params, null, tools.getParameterPage());
}
catch (PRRuntimeError rnfe){
    tools.appendString("PRRuntime Error: "+rnfe.getMessage());
}
catch (PRRuntimeException pre) {
    tools.appendString("PRRuntime Exception: "+pre.getMessage());
}

ClipboardPage cbpRes = tools.findPage("pyValidValuesTemp");
ClipboardProperty cbpResults = cbpRes.getProperty("pxResults");

if (cbpResults.size() > 0){
    boolean valueIsInList = false;
    if (!strValue.equals("")){
        int kk = 0;
        while ((kk < cbpResults.size()) && !valueIsInList){
            ClipboardPage cbpRow = cbpResults.getPageValue(kk+1);
            //tools.appendString("|"+cbpRow.getString("pyFieldValue")+"="+strValue+"|");
            valueIsInList = cbpRow.getString("pyFieldValue").equals(strValue);
            kk++;
        }
    }
    else{
        valueIsInList = true;
    }

    if (!valueIsInList){
        tools.appendString("Value "+StringUtils.crossScriptingFilter(strValue)+" of the property "+StringUtils.crossScriptingFilter(strPropertyName)+" is not defined in the local value list");
    }
    int iX = 0;
    int iY = 0;
    int iListSize = cbpResults.size();
    if (isHorizontal){
        iX = iNumItemsBeforeWrap;
        iY = iListSize / iNumItemsBeforeWrap + ((iListSize % iNumItemsBeforeWrap == 0) ? 0 : 1);
    }
    else{
        iY = iNumItemsBeforeWrap;
        iX = iListSize / iNumItemsBeforeWrap + ((iListSize % iNumItemsBeforeWrap == 0) ? 0 : 1);
    }

    StringMap promptListKeys = new HashStringMap();
    promptListKeys.putString("pzInput", "Display");
    promptListKeys.putString("pxObjClass", "Rule-HTML-Property");
    promptListKeys.putString("pyStreamName", "ClientValidation");

    String[][] strCells = new String[iX][iY];

    for (int k = 0; k < cbpResults.size(); k++){
        int i = 0;
        int j = 0;
        if (isHorizontal){
            i = k % iNumItemsBeforeWrap;
            j = k / iNumItemsBeforeWrap;
        }
        else{
            j = k % iNumItemsBeforeWrap;
            i = k / iNumItemsBeforeWrap;
        }
        ClipboardPage cbpRow = cbpResults.getPageValue(k+1);
        strCells[i][j] = ((i == 0) ? "<tr>" : "") + "<td><input id='"+    strReferenceName+StringUtils.crossScriptingFilter(cbpRow.getString("pyLabel")) +"' type='radio' name='"+strReferenceName+"' value='"+
        StringUtils.crossScriptingFilter(cbpRow.getString("pyFieldValue"))+"' class='Radio'"+
        ((cbpRow.getString("pyFieldValue").equals(strValue))?" checked":"")+" style='vertical-align: middle;'>"+"<label for='"+ strReferenceName+StringUtils.crossScriptingFilter(cbpRow.getString("pyLabel"))+"'>"+StringUtils.crossScriptingFilter(cbpRow.getString("pyLabel"))+"</label></td>"+((i == iX-1) ? "</tr>" : "");
    }
    if (iX*iY != iListSize){
        if (isHorizontal){
            for (int i = 0; i < iX; i++){
                if (strCells[i][iY-1] == null || strCells[i][iY-1].equals("")) strCells[i][iY-1] = "<td>&nbsp;</td>" + ((i == iX-1) ? "</tr>" : "");
            }
        }
        else{
            for (int j = 0; j < iY; j++){
                if (strCells[iX-1][j] == null || strCells[iX-1][j].equals("")) strCells[iX-1][j] = "<td>&nbsp;</td></tr>";
            }
        }
    }

    tools.appendString("<table border=0>");
    for (int j = 0; j < iY; j++){
        for (int i = 0; i < iX; i++){
            int ind = strCells[i][j].indexOf("<input");
            if (ind > -1){
                tools.appendString(strCells[i][j].substring(0,ind+6));
                tools.appendStream(promptListKeys);
                tools.appendString(strCells[i][j].substring(ind+7));
            }
            else{
                tools.appendString(strCells[i][j]);
            }
        }
    }
    tools.appendString("</table>");
}
else{
    tools.appendString("<input type='hidden' name='"+strReferenceName+"' value='"+
                StringUtils.crossScriptingFilter(strValue)+"' />"+StringUtils.crossScriptingFilter(strValue));
}
%>

</pega:when>
<pega:otherwise>
    <pega:reference name="$this-value" mode="normal" />
</pega:otherwise>
</pega:choose>


</pega:otherwise>
</pega:choose>
<pega:when test='param.ReadOnlySmartInfo != "" || param.ReadWriteSmartInfo != ""'>
    <pega:include name="EndSmartField" />
</pega:when>


2. Paste the below code in UserWorkForm, which would help call the activity (testABC). This code would call the activity, onclick of the non-auto generated radio button.

<script>
function test(event)
{
var toSetToTrue;
var objevent = pega.util.Event.getTarget(event);
var findRow = objevent.name;
var arr = findRow.split("$");

var getVal = arr[3].split('');
var toSetToTrue = getVal[1]; 

var strActionSF = new SafeURL("SRA4-SRA402App-Work.testABCActivity");
strActionSF.put("Val",toSetToTrue);
pega.u.d.asyncRequest('POST', strActionSF, null);
pega.u.d.refreshSection("AbcSec", "", "");

}
</script>


3. This activity (testABCActivity) can be used to perform any functionality onclick of the radio button.

4. To call refresh section from the activity use below API call in the script (added in UserWorkForm)

pega.u.d.refreshSection : function (sectionName, usingPage, container) {
//your code
}


5. Save and run the use-case.

Published July 29, 2015 - Updated October 8, 2020

Was this useful?

0% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us