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
KeerthanaKeerthana 

Issue with multi picklist javascript

Hi all,

I have a scenario where I have a custom multi picklist from custom object shown in vf page. It has 4 values, only when 4th value is picked a new field is shown via javascript and hidden when others are selected. Now the issue is the validation must be done from front end and I have used javascript and from there to action fucntion and then to controller. Till action function, the flow is as expected but when the controller is called, the values that needs to be inserted are not passed. Please find the code below. Work around is highly appreciated. Thanks.

Save button:

<div class="modal fade" id="addGTModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog model-lg">
                <apex:form styleClass="modal-content" id="theForm">
                    <apex:pageBlock id="pb">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title" id="myModalLabel">Add GT</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="reason" class="col-sm-4 control-label">GT Prefix:</label>
                            <div class="col-sm-8"><apex:inputText value="{!newWhitelistEntry.GT_Start_Range__c}"/></div>
                        </div>                      
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="reason" class="col-sm-4 control-label">Select a GT Preference:</label>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <apex:selectList required="true" id="GtpreferenceId" style="width:170px;height:28px" multiselect="false" size="1" label="Type" value="{!selectedGTpreference}">
                                <apex:selectOptions value="{!GTPreference}"/>
                            </apex:selectList>
                        </div>                      
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="reason" class="col-sm-4 control-label">Source Network:</label>
                            <div class="col-sm-8"><apex:inputText value="{!newWhitelistEntry.Source_Network__c}"/></div>
                        </div>                      
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="reason" class="col-sm-4 control-label">Source Country:</label>
                            <div class="col-sm-8"><apex:inputText value="{!newWhitelistEntry.Source_Country__c}"/></div>
                        </div>                      
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="reason" class="col-sm-4 control-label">TP-OA Preference:</label>
                            <div class="col-sm-8"><apex:inputField id="tpsp" value="{!newWhitelistEntry.TP_OA__c}" onchange="isTPOASpvalue_0()" /></div>
                        </div>  
                    <div class="form-group" id= "specific" style="display:none">
                            <label for="reason" class="col-sm-4 control-label">Enter Specific Value </label>
                                <div class="col-sm-3">
                                    <apex:inputText id="check" value="{!TPspeficValue}" style="width:160px;height:28px"/>
                                </div>
                                <div class="col-sm-5 control-label" style="color:red">
                                    <span ID="errSpecific" class="bold-red"></span>
                                </div>
                        </div>  
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                        <input type="button" value="Save GT" onclick="isCheck('{!newWhitelistEntry}')" /><br /><br />        
                    </div>
                    </apex:pageBlock>
                </apex:form>
            </div>
        </div>
=================================================================

Javascript:


function isCheck(id) {
        alert('id==='+ id);
            if(document.getElementById("pg:theForm:pb:check").value == ''){
                alert('ischeck');
                document.getElementById("errSpecific").innerHTML="Enter specific value ";
                document.getElementById("pg:theForm:pb").focus();
                return false;
            }else{
                alert('in else');
                Addgtpopup('id');
            }
        }   

==================================================================


Action function:


 <apex:actionFunction name="Addgtpopup" action="{!AddGT}" rerender="addGTModal">
            <apex:param name="gtWhiteListId1" value="" assignTo="{!newWhitelistEntry}" />
  </apex:actionFunction>


===================================================================

Controller:
    public SmartHub_GTWhitelist__c newWhitelistEntry {get; set;}



 public void AddGT(){  
      system.debug('inside add gt===='+ newWhitelistEntry);
        if (newWhitelistEntry.Source_Country__c == '' || newWhitelistEntry.Source_Network__c == '' || (newWhitelistEntry.GT_Start_Range__c).trim() == '')
        {
          alert = 'Please make sure you provide a GT, country and network before adding to the whitelist';
          alertType = 'warning';
          return;
        }
        
        if((newWhitelistEntry.TP_OA__c).contains('TP-OA Specific Value')){
           if(!pattern.matches('^[a-zA-Z0-9]{2,12}$',TPspeficValue)){
                    alert = 'Please enter specific value length should be 2 to 12 Character, A–Z or a–z or 0-9';
                    alertType = 'warning';        
                    return;
              }
            }
        
        try {
        system.debug('inside try add gt====');
          newWhitelistEntry.Account__c = getUserAccountId();
          newWhitelistEntry.Description__c = TPspeficValue;
          insert newWhitelistEntry;
        }
Waqar Hussain SFWaqar Hussain SF
User Renderd attribute on apx:selectList instead of javascript. It will definitely help you.

See the below link for more help
http://salesforce.stackexchange.com/questions/125815/rerender-picklist-values-based-on-checkbox