function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dev_MayuriDev_Mayuri 

Issue with <apex:actionRegion> on the VF page

Hi,

 

Please find the below code snippet.

I am using input fields on the VF page and they are required.

When I click on the Previous button instead of Save instead of navigating to the previous page it remains on the same page and show the error message for the required fields. I tried using action region but its not working. I have highlighted the Previous button code.

Please let me know what is going wrong.

 

<apex:page standardController="Molecule__c" recordSetvar="mol" extensions="AddProductController" tabStyle="Opportunity" id="page">

<style>
    .button{
             
        width:80px;         
    }
</style>

<script src="/soap/ajax/24.0/connection.js"></script>
<script src="{!URLFOR($Resource.jQueryFiles, 'js/jquery-1.4.4.min.js')}"/>
<script src="{!URLFOR($Resource.jQueryFiles, 'js/jquery-ui-1.8.7.custom.min.js')}"/>

<script type="text/javascript">

var j$ = jQuery.noConflict();

j$(document).ready(function(){
    
    var netBid = document.getElementById("page:form:opp:blockSec:table:netBidheader:sortDiv");             
    j$(netBid).css("color", "red");
    
    var volPack = document.getElementById("page:form:opp:blockSec:table:volPackheader:sortDiv");    
 
    j$(volPack).css("color", "red");
    
    var opPlan = document.getElementById("page:form:opp:blockSec:table:opPlanheader:sortDiv");         
    j$(opPlan).css("color", "red");

    var opDem = document.getElementById("page:form:opp:blockSec:table:opDemheader:sortDiv");         
    j$(opDem).css("color", "red");

    var probHead = document.getElementById("page:form:opp:blockSec:table:probheader:sortDiv");         
    j$(probHead).css("color", "red");
     
});        

function checkSave(){

    var buttonstatus =document.getElementById("page:form:opp:saveButton").disabled;
         
    if (buttonstatus == false) {

        var op = confirm("Please click \'Save\' before navigating to the next page else information will be lost.\nDo you want to continue ?");
        
        if(op){    

            return true;
             
        }else{
            
            return false;
        }       
    } 
}

function checkValues() {
    alert('inside 11'); 
    var tabl = document.getElementById('page:form:opp:blockSec:table');
    var l = tabl.rows.length;
    l = l - 1;
    
    document.getElementById("errorblock").innerHTML='';
    
    var errFlag = 0;    
    var errIncrFlag = 0;
    var errpWinFlag = 0;
    var errpQuanFlag = 0;
    
    for (i = 0; i < l; i++) {
    
        var salesprice = document.getElementById("page:form:opp:blockSec:table:" + i + ":salesprice").value;        
        var incrOP = document.getElementById("page:form:opp:blockSec:table:" + i + ":optionListOP").value;       
        var incrDF = document.getElementById("page:form:opp:blockSec:table:" + i + ":optionListDF").value;        
        var pWin = document.getElementById("page:form:opp:blockSec:table:" + i + ":probWin").value;
        var quantity = document.getElementById("page:form:opp:blockSec:table:" + i + ":quantity").value;
        
        document.getElementById("page:form:opp:blockSec:table:" + i + ":salesprice").style.border = "";
        document.getElementById("page:form:opp:blockSec:table:" + i + ":optionListOP").style.border = "";        
        document.getElementById("page:form:opp:blockSec:table:" + i + ":optionListDF").style.border = "";
        document.getElementById("page:form:opp:blockSec:table:" + i + ":probWin").style.border = "";
        document.getElementById("page:form:opp:blockSec:table:" + i + ":quantity").style.border = "";
                  
        if (salesprice == "" || salesprice == 0) {
            
            errFlag = 1;          
            document.getElementById("page:form:opp:blockSec:table:" + i + ":salesprice").style.border = "1px solid #FF0000";            
        }
        
        if (incrOP == "") {
            
            errIncrFlag = 1;          
            document.getElementById("page:form:opp:blockSec:table:" + i + ":optionListOP").style.border = "1px solid #FF0000";           
        }
        
        if (incrDF == "") {
            
            errIncrFlag = 1;          
            document.getElementById("page:form:opp:blockSec:table:" + i + ":optionListDF").style.border = "1px solid #FF0000";            
        }
        
        if (pWin == "" || pWin > 100) {
            
            errpWinFlag = 1;         
            document.getElementById("page:form:opp:blockSec:table:" + i + ":probWin").style.border = "1px solid #FF0000";                    
        }  
        
        if (quantity == "" || quantity == 0) {
            
            errpQuanFlag = 1;         
            document.getElementById("page:form:opp:blockSec:table:" + i + ":quantity").style.border = "1px solid #FF0000";                    
        }    
    }
    
    if (errFlag == 1){
        
        document.getElementById('errorblock').innerHTML = document.getElementById('errorblock').innerHTML +'<br/><font color="#CC0000" size=2 >\' Net Bidding Price \' should always be greater than zero.</font>';
    }
    
    if (errIncrFlag == 1){
    
        document.getElementById('errorblock').innerHTML = document.getElementById('errorblock').innerHTML +'<br/><font color="#CC0000" size=2 >\' Inc to Op Plan \' and \' Inc to Dem Forecast \' are required fields.</font>';
    }
    
    if ( errpWinFlag == 1){
    
        document.getElementById('errorblock').innerHTML = document.getElementById('errorblock').innerHTML +'<br/><font color="#CC0000" size=2 >\' Prob. to Win (%) \' can be 0 or less than 100.</font>';
    }
    
    if (errpQuanFlag == 1){
    
        document.getElementById('errorblock').innerHTML = document.getElementById('errorblock').innerHTML +'<br/><font color="#CC0000" size=2 >\'Volume in Packs\' should always be greater than zero.</font>';
    }
 
    if(errFlag == 1 || errIncrFlag == 1 || errpWinFlag == 1 || errpQuanFlag == 1){
        
        return false;    
    }
    
    if(errFlag == 0 && errIncrFlag == 0 && errpWinFlag == 0 && errpQuanFlag == 0){
        
        return true;    
    }
    
}

function showWarning() {

    var saveStatus =document.getElementById("page:form:opp:saveButton").disabled;
         
    if (saveStatus == false) {

        var val = confirm("Please click \'Save\' before exiting the wizard. Click \'Cancel\' to stay on the current page.\nDo you want to continue ?");
        
        if(val){    
            
            return true; 
        }else{
            
            return false;
        }       
    } 
}

</script>

<apex:form id="form">
<apex:pageBlock id="opp" title="Enter Product Details">

    <apex:pageBlockSection columns="1" id="blockSec">
        
        <div id="errorblock">
        </div>

        <apex:pageBlockTable value="{!inputProductsWrapper}" var="p" columns="7" id="table">
           
            <apex:column headerValue="Product">
                <apex:outputText id="proName" value="{!p.proName}"/>   
            </apex:column>
                        
            <apex:column headerValue="Catalog Price">
                <apex:outputText value="{!p.unitPrice}"/>
            </apex:column> 
            
            <apex:column headerValue="Net Bidding Price" id="netBid">
                <apex:inputField value="{!p.opLine.unitPrice}" id="salesprice" rendered="{!NOT(p.saved)}"/>
                <apex:outputLabel value="{!p.opLine.unitPrice}" rendered="{!p.saved}"/>
            </apex:column> 
            
            <apex:column headerValue="Volume in Packs" id="volPack">
                <apex:inputField value="{!p.opLine.quantity}" id="quantity" rendered="{!NOT(p.saved)}"/>
                <apex:outputLabel value="{!p.opLine.quantity}" rendered="{!p.saved}"/>
            </apex:column> 
            
            <apex:column headerValue="Inc to Op Plan" id="opPlan">
                <apex:selectList id="optionListOP" value="{!p.opLine.Incremental_to_Operating_Plan__c}" size="1" rendered="{!NOT(p.saved)}">
                    <apex:selectOption itemValue="" itemLabel="-None-"/>
                    <apex:selectOption itemValue="Yes" itemLabel="Yes"/>
                    <apex:selectOption itemValue="No" itemLabel="No"/>
                </apex:selectList>
                <apex:outputLabel value="{!p.opLine.Incremental_to_Operating_Plan__c}" rendered="{!p.saved}"/>
            </apex:column> 
            
            <apex:column headerValue="Inc to Dem Forecast" id="opDem">
                <apex:selectList id="optionListDF" value="{!p.opLine.Incremental_to_Demand_Forecast__c}" size="1" rendered="{!NOT(p.saved)}">
                    <apex:selectOption itemValue="" itemLabel="-None-"/>
                    <apex:selectOption itemValue="Yes" itemLabel="Yes"/>
                    <apex:selectOption itemValue="No" itemLabel="No"/>
                </apex:selectList>
                <apex:outputLabel value="{!p.opLine.Incremental_to_Demand_Forecast__c}" rendered="{!p.saved}"/>
            </apex:column> 
            
            <apex:column headerValue="Prob. to Win (%)" id="prob">               
                <apex:inputField value="{!p.opLine.Probability_to_Win__c}" id="probWin" rendered="{!NOT(p.saved)}"/>
                <apex:outputLabel value="{!p.opLine.Probability_to_Win__c}" rendered="{!p.saved}"/>
            </apex:column> 

        </apex:pageBlockTable>      
    </apex:pageBlockSection>    
    
    <div class="rolodex">
        <apex:commandLink styleClass="listItem" rendered="{!hasPreviousInputProduct}"/> 
        <apex:commandLink styleClass="listItem" action="{!previousInputProductList}" rendered="{!hasPreviousInputProduct}" onClick="return checkSave()"><span class="listItemPad">Previous</span></apex:commandlink> 
        <apex:commandLink styleClass="listItem" rendered="{!hasNextInputProduct}"/>
        <apex:actionRegion >  
        <apex:commandLink styleClass="listItem" action="{!nextInputProductList}" rendered="{!hasNextInputProduct}" onClick="return checkSave()"><span class="listItemPad">Next</span></apex:commandlink> 
        </apex:actionRegion>   
    </div>
    
    <table width="75%" style="text-align:center;">
        <tr>
            <td>
                <br/>     
                <apex:actionRegion > <apex:commandButton value="Previous" action="{!previousPageProduct}" styleClass="button" onClick="return checkSave()"/> </apex:actionRegion>                        
                <apex:commandButton value="Save" action="{!insertOppProducts}" disabled="{!NOT(saveEnabled)}" styleClass="button" id="saveButton" onclick="return checkValues();"/>
                <apex:commandButton value="Edit" disabled="{!saveEnabled}" styleClass="button" action="{!editOppProducts}"/>
                <apex:commandButton value="Cancel" rendered="{!hasNextInputProduct}" styleClass="button" action="{!cancelPage}"/> 
                <apex:commandButton value="Exit" rendered="{!NOT(hasNextInputProduct)}" styleClass="button" action="{!cancelPage}" onClick="return showWarning()"/> 
            </td>
        </tr>
    </table>    
    
</apex:pageBlock>
</apex:form>

</apex:page>

 

AditiSFDCAditiSFDC

Hi,

 

Have you tried using "immediate" attribute of action function. This attribute will skip all the validation rules and immediately calls the action.

But if you are setting some controller variable also when clicking "Previous" button then it will not be set.

 

Hope this helps.

sivaextsivaext

Hi Dev

 

You can try "immediate attribute" set to false. it skips validation rules. you can use this attribute in command button

Ulas KutukUlas Kutuk
You can use the renderRegionOnly attribute as true,I think this will help you.