Support Article
Radio button selection does not work across pages
Summary
A repeat grid is configured with Page List as source and radio button (pyRowSelected) as one of the columns. When it uses pagination to display ten rows a page, radio buttons selection does not work across the pages in the repeat grid.
Error Messages
Not Applicable
Steps to Reproduce
- Create a repeat grid with Page List as a source and include radio button (pyRowSelected) as one of the columns in the grid.
- Select a row by clicking radio button in one page.
- Move to the next page or any other page.
- Select a row in that page.
Root Cause
Repeat grid does not take care of selecting and clearing the values in Clipboard. When pagination happens, it does not know if it has to deselect any row. The clearing of radio buttons is client-only, even the values do not propagate to the Clipboard.
Resolution
Perform the following local-change:
- Override setOtherRadioToFalse JavaScript (JS) function provided by repeat grid to enhance it and call an Activity in server that maintains the radio buttons states for them.
- Include the following snippet in the UserWorkForm:
<script>
pega.u.d.attachOnload(function() {
if (pega.ui && pega.ui.grid) {
pega.ui.grid.prototype.setOtherRadioToFalse = function(element, event) {
var currentName = element.name;
if (typeof(element.id) == "undefined" || element.id == "")
element.id = currentName.replace(/[\d]/g, "");
var radioButtonsList = pega.util.Dom.getElementsById(element.id, this.gridDiv);
var len = radioButtonsList.length;
for (var i = 0; i < len; i++) {
if (radioButtonsList[i]) {
if (radioButtonsList[i].name != currentName) {
radioButtonsList[i].checked = false;
}
}
}
var currentRowRef = pega.ui.property.toReference(element.name);
// console.log(currentRowRef);
var activityUrl = SafeURL_createFromURL(pega.u.d.url);
activityUrl.put("pyActivity", "@baseclass.SetOtherRadioToFalse");
activityUrl.put("propRef", currentRowRef);
pega.u.d.asyncRequest("POST", activityUrl);
};
}
}, true);
</script>
Create an Activity @baseclass.SetOtherRadioToFalse in server with one Java step and paste the following -
String propertyReference = tools.getParamValue("propRef");
// Get the property name
String propertyName = propertyReference.substring(propertyReference.lastIndexOf('.') + 1);
// Get the page list name
String rowPageRef = propertyReference.substring(0, propertyReference.lastIndexOf('.'));
String pageListRef = rowPageRef.substring(0, propertyReference.lastIndexOf('('));
int rowNumber = Integer.parseInt(rowPageRef.substring(propertyReference.lastIndexOf('(') + 1, propertyReference.lastIndexOf(')')));
// oLog.error(pageListRef + " | " + rowNumber + " | " + propertyName);
Iterator plIterator = tools.getProperty(pageListRef).iterator();
while(plIterator.hasNext()) {
ClipboardPage rowPage = ((ClipboardProperty) plIterator.next()).getPageValue();
if (rowPage.getReference().equals(rowPageRef)) {
rowPage.getProperty(propertyName).setValue(true);
} else {
rowPage.getProperty(propertyName).setValue(false);
}
}
Published September 15, 2016 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.