You need to sign in to do that
Don't have an account?
Joe Hayes
Update text field depending on picklist value before insert.
Hi Everyone,
I have a vf page that adds multiple child records to an object.
I have a controller for this that can add/delete rows etc.
What I want to do is update a text field with some predetermined text based on the picklist value from the vf page.
for example
PICKLIST COLUMN DATE COLUMN TEXT COLUMN
PICKLIST VALUE 1 --- ---
PICKLIST VALUE 2 --- ---
On insert I want to add "Description related to picklist value 1" into the text column for the picklist value 1 row and "Description related to picklist value 2" into the other.
There is no maximum number of rows.
There are 94 different picklist values with descriptions.
I'm guessing I would hold all the description values in the controller some how and then use the picklist value to reference them.
Just not sure how.
This is my vf page and controller so far:
Thanks for your help.
I have a vf page that adds multiple child records to an object.
I have a controller for this that can add/delete rows etc.
What I want to do is update a text field with some predetermined text based on the picklist value from the vf page.
for example
PICKLIST COLUMN DATE COLUMN TEXT COLUMN
PICKLIST VALUE 1 --- ---
PICKLIST VALUE 2 --- ---
On insert I want to add "Description related to picklist value 1" into the text column for the picklist value 1 row and "Description related to picklist value 2" into the other.
There is no maximum number of rows.
There are 94 different picklist values with descriptions.
I'm guessing I would hold all the description values in the controller some how and then use the picklist value to reference them.
Just not sure how.
This is my vf page and controller so far:
<apex:page controller="AddingAssessmentsController"> <style> .homeTab .pageTitleIcon, .individualPalette .homeBlock .pageTitleIcon { background-position: initial; background-image: url('/img/icon/wrench32.png'); } </style> <apex:form > <apex:variable var="rowNum" value="{!0}"/> <apex:pageBlock > <apex:sectionHeader subtitle="Add Assessments"/> <apex:variable var="rowNum" value="{!0}"/> <apex:pageBlockTable value="{!AssessmentList}" var="asst"> <apex:facet name="footer"> <apex:commandLink value="Add" action="{!insertAsstRow}"/> </apex:facet> <apex:column headerValue="Code"> <apex:inputField value="{!asst.Code__c}" required="true"/> </apex:column> <apex:column headerValue="Last Centre Date"> <apex:inputField value="{!asst.LastCentreDate__c}" id="LastCentreDate"/> </apex:column> <apex:column headerValue="Date of Tech Review"> <apex:inputField value="{!asst.DateofTechReview__c}" id="DateOfTechReview"/> </apex:column> <apex:column headerValue="Date Received By Cert Office"> <apex:inputField value="{!asst.Date_Received_By_Cert_Office__c}" id="Date_Received_By_Cert_Office"/> </apex:column> <apex:column headerValue="Assessor"> <apex:inputField value="{!asst.Assessor__c}" id="Assessor"/> </apex:column> <apex:column headerValue="Verifier"> <apex:inputField value="{!asst.Verifier__c}" id="Verifier"/> </apex:column> <apex:column headerValue="Photo Scanned"> <apex:inputcheckbox value="{!asst.Photo_Scanned__c}" id="photoscanned" selected="true"/> </apex:column> <apex:column headerValue="Photo Scan date"> <apex:inputfield value="{!asst.Photo_Scan_Date__c}" id="photo_scan_date"/> </apex:column> <apex:column headerValue="Fastrack"> <apex:inputcheckbox value="{!asst.Fastrack__c}" id="Fastrack"/> </apex:column> <apex:column headerValue="MOT Cert"> <apex:inputcheckbox value="{!asst.MOT_Cert__c}" id="Mot_cert"/> </apex:column> <apex:column headerValue="Pass?"> <apex:inputcheckbox value="{!asst.Pass__c}" id="pass" selected="true"/> </apex:column> <apex:column headerValue="Delete" > <apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delAsstRow}" immediate="true"> <apex:param value="{!rowNum}" name="index" /> </apex:commandLink> <apex:variable var="rowNum" value="{!rowNum+1}"/> </apex:column> </apex:pageBlockTable> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Save" action="{!insertAssessments}"/> <apex:commandButton value="Back" action="{!cancelAssessments}" immediate="true"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
public class AddingAssessmentsController { Id candId; Id centreId; public List<Assessment__c> AssessmentList {get;set;} public Integer rowNum{get;set;} //Add initial Assessment row public AddingAssessmentsController(){ candId = ApexPages.currentPage().getParameters().get('candId'); centreId = ApexPages.currentPage().getParameters().get('centreId'); AssessmentList = new List<Assessment__c>(); AssessmentList.add(new Assessment__c(Candidate__c=candId, pass__c=true, photo_scanned__c=true, Accredited_Centre__c=centreId)); } //Insert AssessmentList and redirect public PageReference insertAssessments(){ insert AssessmentList; PageReference reRender = new PageReference('/'+candId); reRender.setRedirect(true); return reRender; } //Cancel Assessment and redirect page public PageReference cancelAssessments(){ PageReference reRender = new PageReference('/'+candId); reRender.setRedirect(true); return reRender; } //Insert Assessment Row public void insertAsstRow(){ if(AssessmentList.Size()>0){ Assessment__c tmpAssessment = AssessmentList.get(0); AssessmentList.add(new Assessment__c(Candidate__c=candId, Verifier__c=tmpAssessment.Verifier__c, Assessor__c=tmpAssessment.Assessor__c, LastCentreDate__c=tmpAssessment.LastCentreDate__c, DateofTechReview__c=tmpAssessment.DateofTechReview__c, Date_Received_By_Cert_Office__c=tmpAssessment.Date_Received_By_Cert_Office__c, Photo_Scanned__c=tmpAssessment.Photo_Scanned__c, Photo_Scan_Date__c=tmpAssessment.Photo_Scan_Date__c, Fastrack__c=tmpAssessment.Fastrack__c, MOT_Cert__c=tmpAssessment.MOT_Cert__c, Pass__c=tmpAssessment.Pass__c, Accredited_Centre__c=centreId )); } else AssessmentList.add(new Assessment__c(Candidate__c=candId, pass__c=true, photo_scanned__c=true, Accredited_Centre__c=centreId)); } //Delete Assessment Row public void delAsstRow(){ rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index')); AssessmentList.remove(rowNum); } }
Thanks for your help.
Could you please let me know , which is your picklist field?
We can achieve this requirement , by re-render text field on basis on value of picklist field.
Thanks
Picklist field is asst.Code__c
Thanks
Joe