+ Start a Discussion
yvk431yvk431 

Show/Remove required for dependant picklists

HI,

 

I have a requirement to customize few picklists as there were lot of lovs which exceeded the actual limit . FOr now I am fetching the lovs from the object records by querying and assigining the to the custom select options on VFP. But my problem is there are few other dependant picklist which are conditionally manadatory. So is there a way to make the dependant picklists conditionally mandatory on visual force page.

 

--yvk.

Best Answer chosen by Admin (Salesforce Developers) 
yvk431yvk431

Atlast I fgure it out, i just need to use actionSupport for the onchange event of standard Stage picklist. As the action on stage is triggering the validations by default.

 

<apex:pageblockSection id="pbsStgnm">
              <apex:pageBlockSectionItem>
                  <apex:outputLabel value="{!$ObjectType.opportunity.fields.stageName.label}" for="stage"/>
                  <apex:actionRegion>
                    <apex:inputField value="{!Opportunity.stageName}" required="true" >
                       <apex:actionSupport event="onchange" rerender="pbDisp" />  
                    </apex:inputField>     
                  </apex:actionRegion>  
               </apex:pageBlockSectionItem>

 

--yvk

All Answers

sfdcfoxsfdcfox

You can use the "required" attribute on an input element to make it required, possibly conditionally (use a formula, such as {!fieldXRequired} ).

yvk431yvk431

Hi Sfdcfox,

 

I tried that, but the issue was when I am trying to remove the required mark using hte formulae, it still remaining there and showing the validation you "must enter". Please find the mark up below

 

<apex:page standardController="Opportunity" extensions="PopupTest" id="pgDisp" sidebar="false" showheader="false"> 
<apex:form id="frmDisp">  
  <apex:actionFunction name="refreshPicklists" reRender="Prblty,DispCat,Prfmc,pbsDsp"/>
  <apex:pageMessages></apex:pageMessages>
      <apex:pageBlock id="pbDisp">
          <apex:actionFunction name="PSRen" action="{!PrmSubRsn}" reRender="PSRsnPnl,pbsiDisp2" />
          <apex:actionStatus id="loading" onstart="loading(true)" onstop="loading(false)" />
          
         <apex:outputPanel id="PSRsnPnl"> 
         <apex:pageBlockSection columns="1" id="pbsStgnm">
             <apex:inputField value="{!Opportunity.stageName}" required="true" onchange="refreshDisp();"/>
             <apex:inputField value="{!Opportunity.Probability}" required="true" id="prblty"/>
         </apex:pageBlockSection>
         <apex:pageBlockSection columns="1" id="pbsDsp" rendered="{!(Opportunity.stagename = 'Closed Won' || Opportunity.stagename = 'Closed Lost' || Opportunity.stagename = 'Cancelled') }">    
             
             <apex:inputField value="{!Opportunity.Disposition_Reason__c}" required="{!(Opportunity.stagename = 'Closed Won' || Opportunity.stagename = 'Closed Lost' || Opportunity.stagename = 'Cancelled') }"  id="DispCat"/>
             
         
          
       
             <apex:inputField value="{!Opportunity.Performance__c}" required="{!(Opportunity.Disposition_Reason__c = 'Best Value' || Opportunity.Disposition_Reason__c = 'Not Best Value')}" id="Prfmc"/>
             
         </apex:pageBlockSection>       
         <div id="contentLoading" style="display:none;">
                    <div style="text-align: center; border:none,padding:15px,backgroundColor:#000,-webkit-border-radius: 10px,-moz-border-radius:10px,opacity: .5,color:#fff">
                       <FONT FACE="Helvetica,Verdana,Arial" SIZE="3" COLOR="#000066"><B>Please wait...</B></FONT>
                    </div>
                </div>   
         <apex:pageBlockSection id="pbsDisp" columns="1">
             
              <apex:pageblockSectionItem id="pbsiDisp">
                  <apex:outputLabel value="Primary Reason"></apex:outputLabel>
                  <apex:actionRegion >
                    
                        <apex:selectList value="{!selectedPRsn}" onchange="getSubReason();" onblur="getSubReason();" onfocus="showDetail(this, 'Primary');" id="selPicklistPRsn"  size="1" >
                           <apex:selectOptions value="{!PRsn}"/>
                        </apex:selectList>
                       <div id="Primary_description" style="display:none;">
                                    <apex:outputText value="{!PrmdescriptionString}" escape="false" />
                                </div>  
                  </apex:actionRegion>
                                    
                   
                                               
              </apex:pageblockSectionItem>
              <apex:pageblockSectionItem id="pbsiDisp2">
                  <apex:outputLabel value="Primary Sub Reason"></apex:outputLabel>
                  <apex:actionRegion > 
                                      
                        <apex:selectList value="{!selectedPSRsn}" onchange="hideDetail();" onblur="hideDetail();" onfocus="showDetail(this, 'Sub');" id="selPicklistPSRsn"  size="1" disabled="{!selectedPRsn = ''}">
                           <apex:selectOptions value="{!PSRValues}"/>
                        </apex:selectList>    
                          <div id="Sub_description" style="display:none;">
                                    <apex:outputText value="{!PrmSbdescriptionString}" escape="false" />
                                </div>             
                  </apex:actionRegion>                                                                                                      
              </apex:pageblockSectionItem>
             
            </apex:pageBlockSection>
          </apex:outputPanel>       
          <apex:pageBlockButtons location="bottom" id="pgblkBtn">              
              <apex:commandButton value="Save" action="{!Save}" oncomplete="javascript&colon;window.close();"/>
              <apex:commandButton value="Cancel" id="bckBtn" onclick="javascript&colon;window.close();" immediate="false"/>
          </apex:pageBlockButtons>
           
                               
                            
          <apex:outputText value="{!Opportunity.stagename}" rendered="false"/>
          <apex:outputText value="{!Opportunity.RecordType.Name}" rendered="false"/>
          <apex:outputText value="{!Opportunity.Primary_Reason__c}" rendered="false"/>
          <apex:outputText value="{!Opportunity.Primary_Sub_Reason__c}" rendered="false"/>
      </apex:pageBlock>
  </apex:form>
  <script>
      function showDetail(el, id) {
            //var Prm = document.getElementById("pgDisp:frmDisp:pbDisp:pbsDisp:pbsiDisp:selPicklistPRsn");
            var td = jQuery(el).parent().parent();
            var tr = td.parent();
            var riskFactorCell = td.prev();
            var CategoryCell = riskFactorCell.prev();
            var popupWidth = riskFactorCell.width() + CategoryCell.width();           
            var riskFactorOffset = riskFactorCell.offset();
            var eleOffset = CategoryCell.offset();
            var description = jQuery("#"+id+"_description").html();                       
            jQuery("#deviationInner").html(description);
            jQuery("#deviationDescription").css('width', 250);
            jQuery("#deviationDescription").css('position', 'absolute');
            jQuery("#deviationDescription").css('right', 25);
            jQuery("#deviationDescription").css('top', 50);
            var tableHeight = jQuery("#pbsDisp").height();
            jQuery("#deviationDescription").fadeIn();
        }
        
        
       
        function hideDetail() {
            jQuery("#deviationDescription").hide();
            document.getElementById("pgDisp:frmDisp:pbDisp:pgblkBtn:bckBtn").focus();
        }
        
        function getSubReason()
        {
            hideDetail();
            PSRen();
        }
        
        function loading(val) {
           if (val) {
              document.getElementById('contentLoading').style.display = 'block';
             
            }
            else {
              document.getElementById('contentLoading').style.display = 'none';
              
            }
       }
       
       function refreshDisp()
       {
           
           refreshPicklists();
       }
      
  </script>

 THe custom picklists functionality is working fine, all i wanted is to mimic the standard dependancy functionality between stage, probability, Disposition Info. Can you please suggest any work around in this regard.

 

Thanks

--yvk

yvk431yvk431

Atlast I fgure it out, i just need to use actionSupport for the onchange event of standard Stage picklist. As the action on stage is triggering the validations by default.

 

<apex:pageblockSection id="pbsStgnm">
              <apex:pageBlockSectionItem>
                  <apex:outputLabel value="{!$ObjectType.opportunity.fields.stageName.label}" for="stage"/>
                  <apex:actionRegion>
                    <apex:inputField value="{!Opportunity.stageName}" required="true" >
                       <apex:actionSupport event="onchange" rerender="pbDisp" />  
                    </apex:inputField>     
                  </apex:actionRegion>  
               </apex:pageBlockSectionItem>

 

--yvk

This was selected as the best answer