You need to sign in to do that
Don't have an account?
Staci
set default picklist value in VF Page
All I want to do is set the default value in a Status picklist to Implemented when the button is clicked. It doesn't even need to be displayed in the pop-up. Just when Save is clicked and the page renders back to the change record, the Status needs to be Implemented. Is that possible without a controller?
Code
<apex:page standardController="Change__c" extensions="impStartEnd"> <apex:form id="frm"> <apex:detail subject="{!Change__c.Id}" relatedList="false" title="false"/> <apex:outputPanel id="tstpopup" rendered="{!IF(isDisplayPopUp ==true,true,false)}" > <apex:outputPanel styleClass="popupBackground" layout="block" /> <apex:outputPanel styleClass="custPopup" layout="block"> <apex:pageMessages > </apex:pageMessages> <apex:pageBlock > <apex:pageBlockSection > <apex:inputField label="Actual Implementation Start Date / Time" value="{!Change__c.Implementation_Start_Date_Time__c}"/> <apex:inputField label="Actual Implementation End Date / Time" value="{!Change__c.Implementation_End_Date_Time__c}"/> <apex:outputPanel > <apex:CommandButton action="{!save}" value="Save!"/> <apex:CommandButton action="{!cancel}" value="cancel"/> </apex:outputPanel> </apex:pageBlockSection> </apex:pageBlock> </apex:outputPanel> </apex:outputPanel> </apex:form> <style type="text/css"> .errorMsg{ width:159px; } .custPopup{ background-color: white; border-width: 3px; border-style: solid; z-index: 9999; left: 25%; padding:10px; position: absolute; width: 800px; //margin-left: -80px; top:100px; margin-left: -170px; //top:305px; border-radius: 5px; } .datePicker{z-index:10000} .popupBackground{ background-color:black; opacity: 0.20; filter: alpha(opacity = 20); position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 997 } a.actionlink:hover{ text-decoration:underline; } .customactionLink { color: #015BA7; font-weight: normal; text-decoration: none; } </style> <script> function setFocusOnLoad() { } </script> </apex:page>
1) You can bind the value of the picklist to the field of your object so whatever the value of the field is that is what the dropdown will be set to
2) You don't have to worry about Salesforce making a change to the HTML structure of components and breaking the page.
Just to summarize if you can bind the value to a field in the controller then it's often better to do that. If you need to use javascript just be aware that you might have to make changes down the road to accommodate changes made by Salesforce.
Thanks Dave
How do I bind it in the controller?
This is all my controller does right now
Here is an example right from the docs:
So you can see there is a var in the controller named "selectedCountry" and it get's bound to the value attrib for the selectList. When the page is loaded it will pull the default value (if any) of selectedCountry and on form submit whatever the user has selected will get assigned to selectedCountry.
Ok almost there! I get the default now, but when I click Save, it doesn't update the record.
Page:
Class: