You need to sign in to do that
Don't have an account?
Joe Hayes
VF Booking Page Problem
I am designing a vf page to book people onto different events that we run.
The page has a rows asking for name, phone etc and the event that they want to be booked on.
Once the user presses save it adds the list of new records (Event_Delegates__c).
It all works fine and does what I need it to do apart from one thing. When I add a row into the table it resets the venuex SelectList and clears the information. I am not sure where the issue is in the code.
Page:
Controller:
If someone could give me some pointers it would be really helpful,
Thanks
The page has a rows asking for name, phone etc and the event that they want to be booked on.
Once the user presses save it adds the list of new records (Event_Delegates__c).
It all works fine and does what I need it to do apart from one thing. When I add a row into the table it resets the venuex SelectList and clears the information. I am not sure where the issue is in the code.
Page:
<apex:page sideBar="false" controller="BookEventsTest"> <style> .homeTab .pageTitleIcon, .individualPalette .homeBlock .pageTitleIcon { background-position: initial; background-image: url('/img/icon/profile32.png'); } .dateFormat{ display: none; } </style> <script> function updatehidden() { var sellist = document.querySelectorAll("[data-sellist]"), inpfield = document.querySelectorAll("[data-inpfield]"), inpnew = document.querySelectorAll("[data-inpnew]"), for (var i = 0; i < inpfield.length; i++) { inpnew[i].value = sellist[i].value + ' - ' + inpfield[i].value; } } function setvenue() { var venue = document.querySelectorAll("[data-venue]"), venuenew = document.querySelectorAll("[data-venuenew]"), datenew = document.querySelectorAll("[data-datenew]"); for (var i = 0; i < inpfield.length; i++) { venuenew[i].value = venue[i].value.substring(11,255); datenew[i].value = venue[i].value.substring(0,8); } } </script> <apex:form > <apex:variable var="rowNum" value="{!0}"/> <apex:pageBlock > <apex:sectionHeader subtitle="Add Event Delegates"/> <apex:variable var="rowNum" value="{!0}"/> <apex:pageBlockTable value="{!DelegateList}" var="del" style="width:100%"> <apex:facet name="footer"> <apex:commandLink value="Add" action="{!insertDelRow}"/> </apex:facet> <apex:column headerValue="Name" style="width:10%"> <apex:inputField style="width:98%" value="{!del.Name__c}" id="inpfield" required="true" html-data-inpfield="1" onchange="updatehidden()"/> </apex:column> <apex:column headerValue="Phone" style="width:10%"> <apex:inputField style="width:98%" value="{!del.Phone__c}" onchange="updatehidden()" id="phone"/> </apex:column> <apex:column headerValue="Email" style="width:12%"> <apex:inputField style="width:98%" value="{!del.Email_Address__c}" onchange="updatehidden()" id="email" required="true"/> </apex:column> <apex:column headerValue="Job Role" style="width:10%"> <apex:inputField style="width:98%" value="{!del.Job_Role__c}" onchange="updatehidden()" id="jobrole"/> </apex:column> <apex:column headerValue="Company Name" style="width:12%"> <apex:inputField style="width:85%" value="{!del.Company_Name__c}" id="companyname" onchange="updatehidden()" required="true"/> </apex:column> <apex:column headerValue="Event Type" style="width:11%"> <apex:actionRegion > <apex:selectList style="width:98%" value="{!selectedType}" multiselect="false" html-data-sellist="1" size="1" id="sellist"> <apex:selectOption itemValue="Type1" itemLabel="Type1"/> <apex:selectOption itemValue="Type2" itemLabel="Type2"/> <apex:selectOption itemValue="Type3" itemLabel="Type3"/> <apex:actionSupport event="onchange" reRender="venue"/> </apex:selectList> </apex:actionRegion> </apex:column> <apex:column headerValue="Venue" style="width:20%"> <apex:selectList value="{!venuex}" style="width:98%" html-data-venue="1" size="1" id="venue" onchange="setvenue()"> <apex:selectOptions value="{!venues}"/> </apex:selectList> </apex:column> <apex:column headerValue="FOC?"> <apex:inputcheckbox value="{!del.FOC__c}" onchange="updatehidden()" id="foc"/> </apex:column> <apex:column headerValue="Delete" style="width:3%"> <apex:commandLink style="font-size:15px; font-weight:bold; padding-left:30%; color:red;" value="X" action="{!delDelRow}" immediate="true"> <apex:param value="{!rowNum}" name="index"/> </apex:commandLink> <apex:variable var="rowNum" value="{!rowNum+1}"/> <apex:inputHidden value="{!del.Name}" html-data-inpnew="1" id="inpnew"/> <apex:inputHidden value="{!del.Event_Date__c}" html-data-datenew="1" id="datenew"/> <apex:inputHidden value="{!del.Venue__c}" html-data-venuenew="1" id="venuenew"/> </apex:column> </apex:pageBlockTable> <br/> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Save" action="{!insertDelegates}"/> <apex:commandButton value="Back" action="{!cancelDelegates}" immediate="true"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Controller:
public class BookEventsTest { public List<Event_Delegates__c> DelegateList {get;set;} public Integer rowNum{get;set;} public String selectedType{get;set;} public String venuex{get;set;} //Add initial Delegate row { selectedType = 'Type1'; venuex = ''; DelegateList = new List<Event_Delegates__c>(); DelegateList.add(new Event_Delegates__c()); } //Insert DelegateList and redirect public PageReference insertDelegates(){ insert DelegateList; PageReference reRender = new PageReference('/'); reRender.setRedirect(true); return reRender; } //Cancel Delegate and redirect page public PageReference cancelDelegates(){ PageReference reRender = new PageReference('/'); reRender.setRedirect(true); return reRender; } //Insert Delegate Row public void insertdelRow(){ if(DelegateList.Size()>0){ Event_Delegates__c tmpdel = DelegateList.get(0); DelegateList.add(new Event_Delegates__c( phone__c=tmpdel.phone__c, email_address__c=tmpdel.email_address__c, company_name__c=tmpdel.Company_Name__c, venue__c=tmpdel.venue__c )); } else DelegateList.add(new Event_Delegates__c()); } //Delete Delegate Row public void delDelRow(){ rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index')); DelegateList.remove(rowNum); } //Display correct picklist depending on selectType public List<SelectOption> getVenues(){ List<SelectOption> venueoptions = new List<SelectOption>(); if(selectedType=='Type1'){ Schema.DescribeFieldResult fieldResult = Event_Delegates__c.type1__c.getDescribe(); List<Schema.PicklistEntry> venues = fieldResult.getPicklistValues(); for( Schema.PicklistEntry v : venues) { venueoptions.add(new SelectOption(v.getLabel(), v.getValue())); } } else if(selectedType=='Type2'){ Schema.DescribeFieldResult fieldResult = Event_Delegates__c.type2__c.getDescribe(); List<Schema.PicklistEntry> venues = fieldResult.getPicklistValues(); for( Schema.PicklistEntry v : venues) { venueoptions.add(new SelectOption(v.getLabel(), v.getValue())); } } else if(selectedType=='Type3'){ Schema.DescribeFieldResult fieldResult = Event_Delegates__c.type3__c.getDescribe(); List<Schema.PicklistEntry> venues = fieldResult.getPicklistValues(); for( Schema.PicklistEntry v : venues) { venueoptions.add(new SelectOption(v.getLabel(), v.getValue())); } } else{} return venueoptions; } }
If someone could give me some pointers it would be really helpful,
Thanks
Joe Hayes
Page looks like this, it is the venue column that is resetting to the default value in the picklist once the 'add' button is used.