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

When validation errors are present, focus keeps shifting to top

SA-34126

Summary



When error messages are set using Property-Set-Message / Page-Set-Message on top of harness, error is shown as expected.
However, when the user scrolls down to change the data as per the error message, system taking the focus to the top of the screen.


Error Messages



Not Applicable


Steps to Reproduce



1) Create a section which contains grid.
2) Add few properties in the grid that has few validation set.
3) Configure the harness to display form level errors to display as "Top of the harness"
4) At run time observe that when there are error messages present on the form, we are not able to modify the properties.


Root Cause



When validation errors are present, focus keeps shifting to top.

Resolution



Perform the following local-change:

Add the below code in the UserWorkform:
<script>
$(document).ready(function(){
setTimeout(function(){
var p = pega || {};
if (!p.control) {
p.c = p.namespace("pega.control");
} else {
p.c = pega.control;
}
if (!p.c.Actions) {
p.c.Actions = function() {};
} else {
p.c.Actions = pega.control.Actions;
}

pega.control.Actions.prototype.showSmartTip = function(event, format, tipMsg, headerMsg) {
var targetElement = pega.util.Event.getTarget(event);
if (targetElement.__SmartTipVisible == undefined || targetElement.__SmartTipVisible == null) {
targetElement.__SmartTipVisible = true;
var bodyMouseMoveHandler = function(e) {
var sourceEle = pega.util.Event.getTarget(e);
var eventX = pega.util.Event.getPageX(e);
var eventY = pega.util.Event.getPageY(e);
var currEle = p.c.mouseOverEle;
var eleLeft = pega.util.Dom.getX(currEle);
var eleTop = pega.util.Dom.getY(currEle);
var eleRight = eleLeft + currEle.offsetWidth;
var eleBottom = eleTop + currEle.offsetHeight;
if (!isNaN(eleRight) && !isNaN(eleBottom) && !((eventX >= eleLeft && eventX <= eleRight) && (eventY >= eleTop && eventY <= eleBottom))) {
p.u.d.getPopOver(targetElement).close()
}
};
var smartTipBeforeCloseHandle = function() {
pega.util.Event.removeListener(document.body, "mousemove", bodyMouseMoveHandler);
targetElement.__SmartTipVisible = undefined;
var idOfHiddenATSpanElement = targetElement.getAttribute("aria-describedby");
var hiddenATSpanElement = document.getElementById(idOfHiddenATSpanElement);
if (hiddenATSpanElement) {
document.body.removeChild(hiddenATSpanElement)
}
if (!window.chrome) {
targetElement.removeAttribute("role")
}
targetElement.removeAttribute("aria-label");
targetElement.removeAttribute("aria-describedby");
targetElement.removeAttribute("aria-labelledby");
targetElement.removeAttribute("aria-controls");
targetElement.removeAttribute("aria-owns");
return true
};
var contElem = document.createElement("div");
if (headerMsg !== undefined) {
var header = document.createElement("div");
header.innerHTML = headerMsg;
header.className = "smarttip-header";
contElem.appendChild(header)
}
var tip = document.createElement("div");
tip.innerHTML = tipMsg;
tip.className = "smarttip-content";
contElem.appendChild(tip);
var tempElem = document.createElement("div");
tempElem.appendChild(contElem);
var _popOver = p.u.d.getPopOver(targetElement);
var contentClass = "smarttip-container";
if (format != "") {
contentClass += " smarttip-container-" + format
}
_popOver.open({
content: {
type: "domElement",
element: tempElem
},
buttons: {
ok: false,
cancel: false
},
bindings: {
associatedElement: targetElement
},
visual: {
displayLoader: false,
contentClass: contentClass,
arrowDivClasses: ["arrow top", "arrow bottom", "arrow right", "arrow left"]
},
position: {
fieldAttach: "leftBottom",
popOverAttach: "leftTop",
size: {
min: {
x: 20,
y: 20
}
},
offsetAttach: {
y: 7
}
},
extraParams: {
refresh: false,
overflow: false
},
callbacks: {
onBeforeClose: smartTipBeforeCloseHandle
}
});
targetElement.focus();
targetElement.blur();
function _generateAccessibleText(tMsg, hMsg) {
if (!hMsg || (typeof hMsg != "string")) {
hMsg = ""
} else {
if (/\.$/.test(hMsg)) {
hMsg += " "
} else {
hMsg += ". "
}
}
if (!tMsg || (typeof tMsg != "string")) {
tMsg = ""
} else {
if (!(/\.$/.test(tMsg))) {
tMsg += "."
}
}
var accessibleSmartTipText = hMsg + tMsg;
return ( accessibleSmartTipText)
}
function _generateUniqueHTMLElementId() {
var rndNum = Math.random();
rndNum = rndNum.toString().replace("0.", "");
return ( "stc" + rndNum)
}
var idOfHiddenATSpanElement = _generateUniqueHTMLElementId();
var readableATText = _generateAccessibleText(tipMsg, headerMsg);
var hiddenATSpanElement = document.createElement("span");
hiddenATSpanElement.innerHTML = readableATText;
hiddenATSpanElement.setAttribute("id", idOfHiddenATSpanElement);
hiddenATSpanElement.setAttribute("role", "tooltip");
hiddenATSpanElement.style.display = "none";
document.body.appendChild(hiddenATSpanElement);
if (!window.chrome) {
targetElement.setAttribute("role", "dialog")
}
targetElement.setAttribute("aria-label", readableATText);
targetElement.setAttribute("aria-describedby", idOfHiddenATSpanElement);
targetElement.setAttribute("aria-labelledby", idOfHiddenATSpanElement);
targetElement.setAttribute("aria-controls", idOfHiddenATSpanElement);
targetElement.setAttribute("aria-owns", idOfHiddenATSpanElement);
if (pega && pega.u && pega.u.d && pega.u.d.isAccessible) {
targetElement.focus()
}
p.c.mouseOverEle = targetElement;
pega.util.Event.addListener(document.body, "mousemove", bodyMouseMoveHandler);
var popOverContainerElem = _popOver.getContentContainerElement();
var arrowBorderDiv = pega.util.Dom.getElementsById("arrow-border", popOverContainerElem, "DIV");
if (headerMsg == undefined) {
if (arrowBorderDiv[0].className.indexOf("noHeader") === -1) {
pega.util.Dom.addClass(arrowBorderDiv[0], "noHeader")
}
} else {
if (arrowBorderDiv[0].className.indexOf("noHeader") !== -1) {
pega.util.Dom.removeClass(arrowBorderDiv[0], "noHeader")
}
}
}
}
},500);
});
</script>

Suggest Edit

Published March 10, 2017 - Updated October 8, 2020

Did you find this content helpful? Yes No

Have a question? Get answers now.

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

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