I have a vf page with country and geography fields. Geography field is an autocomplete field.
Upon selection of country field, geography field list gets populated. Ex - 1.If users selects United Arab Emirates, Geography fields populates values
- A, B, C, D. ------User selected A, B.
- Then if the user selects country as United States, Geography field gets rerender and the value A,B is lost.
I need to retain the old values and also add the new values.
Below is my class and Vf Page -
Class -
public class RfpControllerExtension2 {
public string model{get;set;}
public List<String> SelectedDept{get;set;}
public List<Geography__c> results{get;set;}
public List<SelectOption> AllDept{get;set;}
public List<SelectOption> AllName{get;set;}
public List<String> SelectedName{get;set;}
public String discountScheduleID { get; set; }
public RfpControllerExtension2 (){
AllDept= new List<SelectOption>();
AllDept= getDept();
AllName= new List<SelectOption>();
AllName= getName();
}
public void FindAllName()
{
system.debug('@@@@@@ Entered');
AllName= new List<SelectOption>();
AllName= getName();
}
public List<SelectOption> getDept()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Select','--Select--'));
Schema.DescribeFieldResult departfield = Geography__c.Country__c.getDescribe();
List<Schema.PicklistEntry> picklist = departfield.getPicklistValues();
for( Schema.PicklistEntry f : picklist){
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public List<SelectOption> getName()
{
List<SelectOption> options = new List<SelectOption>();
Set<String> sProj = new Set<String>();
if(discountScheduleID != null )
{
for(Geography__c Proj :[select Id, Canonical_Name__c, Type__c from Geography__c where status__c = 'active' AND Country__c =: discountScheduleID order by Canonical_Name__c] )
{
options.add(new SelectOption(Proj.ID,Proj.Canonical_Name__c));
}
}
return options;
}
public Map<String, String> errorMap {
get {
if (errorMap == null || errorMap.size() == 0) {
errorMap = new Map<String, String> {
'selectedGeographies' => '',
'flightDates' => '',
'agency' => '',
'agencyContact' => ''
};
}
return errorMap;
}
private set;
}
}
VF Page -
<apex:page controller="RfpControllerExtension2">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<c:FixSfdcFocusHack />
<c:JQuery />
<c:Chosen />
<style type="text/css">
.fullWidth { width: 100%; }
.flightDateRangeText { font-size: 90%; }
.bPageBlock .requiredForSubmit .requiredBlock {
background-color: #FFD700;
bottom: 1px;
left: -4px;
position: absolute;
top: 1px;
width: 3px;
}
.bPageBlock .requiredForSubmitInput {
height: 100%;
position: relative;
}
</style>
<script type="text/javascript">
/* <![CDATA[ */
/*
* Render Chosen on select elements with the chzn-select class specified.
*/
function renderChosen() {
$j('.chzn-select').chosen();
}
/*
* Render required marker on elements where class == "required".
*/
function renderRequired() {
$j('.required').wrap('<div class="requiredInput" />').before('<div class="requiredBlock" />');
}
/*
* Render required marker on elements with the specified ID.
*/
function renderRequiredComponentId(componentId) {
$j(jq(componentId) + ' .required').wrap('<div class="requiredInput" />').before('<div class="requiredBlock" />');
}
var rfpRequiredIds = ["dueDate", "clientsEstablishedPartners", "campaignMarketingObjectives", "campaignGoals",
"scopeOfCampaign", "mediaRequested", "otherMediaRequested", "campaignTotalNet",
"primaryTargetAudience", "geographies", "servingPreference", "clientServedSpecifics", "adSizes",
"creativeType", "richMediaType", "percentageFlash", "percentageRichMedia", "flightDateRanges"];
var optRequiredFieldIds = ["planCompletionDate", "clientsEstablishedPartners",
"campaignMarketingObjectives", "campaignGoals", "scopeOfCampaign", "mediaRequested", "campaignComments",
"primaryTargetAudience", "geographies", "customGeoDetail", "servingPreference", "clientServedSpecifics",
"adSizes", "creativeType", "richMediaType", "additionalCreativeNotes"];
//SSirikonda - 07/25/2013 - Removing the field Plan_completion_Date__c as yellow marked field when
//RFP type drop-down = SEM
/*var semRequiredFieldIds = ["planCompletionDate", "url",
"campaignMarketingObjectives", "campaignComments", "geographies", "customGeoDetail"];*/
var semRequiredFieldIds = ["url",
"campaignMarketingObjectives", "campaignComments", "geographies", "customGeoDetail"];
function modifyRequired() {
$j('.requiredForSubmitInput').removeClass('requiredForSubmitInput');
var type = $j('[id$="type"]').val();
if (type == 'RFP') {
$j.each(rfpRequiredIds, function(index, value) {
var selector = '[id$="' + value + '"]';
$j(selector).addClass('requiredForSubmitInput');
});
} else if (type == 'OPT') {
$j.each(optRequiredFieldIds, function(index, value) {
var selector = '[id$="' + value + '"]';
$j(selector).addClass('requiredForSubmitInput');
});
} else if (type == 'SEM') {
$j.each(semRequiredFieldIds, function(index, value) {
var selector = '[id$="' + value + '"]';
$j(selector).addClass('requiredForSubmitInput');
});
}
}
function changePrimaryContact() {
var value = $j('[id$="primaryContact"]').val();
var selector = '[id$="agencyContact"]';
$j(selector).removeClass('requiredInput');
var selector = '[id$="agency"]';
$j(selector).removeClass('requiredInput');
if (value == 'Agency') {
var selector = '[id$="agency"]';
$j(selector).addClass('requiredInput');
var selector = '[id$="agencyContact"]';
$j(selector).addClass('requiredInput');
}
}
$j(document).ready(function() {
renderChosen();
renderRequired();
changePrimaryContact();
modifyRequired();
});
/* $(".chzn-select").chosen().change(function() {
function(){
renderChosen();
alert("test");
}
});
*/
/* ]]> */
</script>
<apex:form id="form">
<apex:pageMessages />
<apex:selectList value="{!discountScheduleID}" size="1" styleClass="fullWidth chzn-select">
<apex:actionSupport event="onchange" action="{!FindAllName}" rerender="geographies" oncomplete="renderChosen()"/>
<apex:selectOptions value="{!dept}" />
</apex:selectList>
<apex:outputLabel value="{!$ObjectType.RFP__c.Fields.Geography__c.Label}" />
<apex:outputPanel id="geographies" layout="block" styleClass="requiredInput">
<apex:outputPanel id="geos" layout="block" styleClass="requiredBlock"/>
<apex:selectList value="{!SelectedName}" multiselect="true" id="selectedGeographies" styleClass="fullWidth chzn-select" >
<apex:selectOptions value="{!AllName}" id="movieTextBox"></apex:selectOptions>
</apex:selectList>
<apex:outputPanel layout="block" styleClass="errorMsg" >
<apex:outputText value="{!errorMap['selectedGeographies']}"
escape="false" rendered="{!errorMap['selectedGeographies'] != ''}" />
</apex:outputPanel>
</apex:outputPanel>
</apex:form>
</apex:page>