Monday 18 July 2016

Blank Row Restriction in Oracle APEX

Blank Row Restriction is to avoid unwanted addition of rows in detail report (tabular Form) when a blank row already exists. This functionality can be achieved by Javascript. It is simple but can be reused everywhere.

Step:1:
Change Add Row Button action as “Defined by Dynamic Action”

Step:2:
Create Dynamic Action with action as

Event : Click Button
Action : Execute Javascript Code
Code :
var i = 1;
var count = 0;
var c;
while (i != 0) {
b = "000" + i;
//alert(b);
b = pad(i,4);                     // calls function pad and pads 4     zeros
a = $x("f05_" + b).value;           // id of mandatory column
//alert(a);
if (typeof a === "undefined") {
i = 0;
} else {
c = a.trim();
if (c.length == 0) {
count = count + 1;
} else {
count = 0;
}
i = i + 1;
}

}
if (count == 0) {
javascript:apex.widget.tabular.addRow();              // Adds New    Row
//javascript:addRowTop();            
}
else {
$("#alert").html("Blank row already exists. Hence cannot add row");
 $("#alert").dialog({modal:true,resizable: false,minHeight: 105,width:380,dialogClass: 'testclass'});
}
// Alert displayed with Jquery Dialog . For Better include Class as testclass and style elements, Otherwise Ignore it
 function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}

CSS : (Include CSS as Inline CSS)

.testclass .ui-dialog-titlebar
{
    background:#00433c !important;
    color:white !important;
}
.testclass .ui-dialog
    top:50px !important;
}
.testclass .ui-dialog-title
{
    color:white !important;
    font-family: 'Helvetica Neue','Segoe UI',Helvetica,Arial,sans-serif !important;
    margin-left:10px !important;
}
.testclass .body-content
{
    /* Blur and de-color */
  -webkit-filter: blur(5px) grayscale(50%);

  /* Recede */
  -webkit-transform: scale(0.9);

}
.testclass .ui-dialog-content
{  
  overflow:hidden !important;   
  font-family: 'Helvetica Neue','Segoe UI',Helvetica,Arial,sans-serif !important;
  font-size:14px !important;  
  margin-top:12px !important; 
  margin-left:10px !important;  
} 

Output:

No comments:

Post a Comment