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
kmorf_entransformkmorf_entransform 

dynamic picklist

im trying to write a visualforce page where you can create a new custom object project. the field status in object Project is a picklist. i want to be able to make a new picklist value when selecting "--other--" in a drop down. when "--Other--" is selected an inputText should be rendered and you are able to enter the new picklist value from the inputText. My code doesnt seem to work. if u select Other from the dropdown. the inputText does not appear.

<apex:page standardController="Proj__c" tabStyle="Proj__c">
  <apex:sectionHeader title="Create Project"/>
    <apex:form id="Header">
      <apex:pageBlock title="General Information" mode="edit">
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection columns="2">
           <apex:inputField required="true" value="{!Proj__c.Name}"/>
           <apex:inputField required="true" value="{!Proj__c.Expense_Budget__c}"/>
            <apex:inputField required="true" value="{!Proj__c.Billable_hours__c}"/> 
            <apex:inputField required="true" value="{!Proj__c.Location__c}"/>
         
           <apex:inputField value="{!Proj__c.Status__c}" id="values">             
            <apex:actionSupport event="onchange" reRender="newvalue" />              
           </apex:inputField>  
             
      
                                               
      
       <apex:outputpanel id="newvalue" >
       <apex:outputpanel rendered="{!Proj__c.Status__c == '--Other--'}">       
                
        <div style="position:relative;left:75px;"> 
        <apex:outputlabel value="new value" for="newval1"/>                            
          <apex:inputText value="{!Proj__c.Status__c}" id="newval1"/>              
              </div>            
        </apex:outputpanel>
         </apex:outputpanel>
        
        
                         
              </apex:pageBlockSection>    
   
    </apex:pageBlock>
     </apex:form>
</apex:page>

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Devendra NataniDevendra Natani

Hello,

 

Please use the below code. I have put <apex:actionregion > tag.

 

<apex:page standardController="Proj__c" tabStyle="Proj__c">
  <apex:sectionHeader title="Create Project"/>
    <apex:form id="Header">
<apex:actionFunction name="validate" reRender="newvalue"/> <apex:pageBlock title="General Information" mode="edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection columns="2"> <apex:inputField required="true" value="{!Proj__c.Name}"/> <apex:inputField required="true" value="{!Proj__c.Expense_Budget__c}"/> <apex:inputField required="true" value="{!Proj__c.Billable_hours__c}"/> <apex:inputField required="true" value="{!Proj__c.Location__c}"/> <apex:actionRegion>  <apex:inputField value="{!Proj__c.Status__c}" id="values"> <apex:actionSupport event="onchange" reRender="newvalue" /> </apex:inputField> </apex:actionRegion>  <apex:outputpanel id="newvalue" > <apex:outputpanel rendered="{!Proj__c.Status__c == '--Other--'}"> <div style="position:relative;left:75px;"> <apex:outputlabel value="new value" for="newval1"/> <apex:inputText value="{!Proj__c.Status__c}" id="newval1"/> </div> </apex:outputpanel> </apex:outputpanel> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

All Answers

Devendra NataniDevendra Natani

Hello,

 

Please use the below code. I have put <apex:actionregion > tag.

 

<apex:page standardController="Proj__c" tabStyle="Proj__c">
  <apex:sectionHeader title="Create Project"/>
    <apex:form id="Header">
<apex:actionFunction name="validate" reRender="newvalue"/> <apex:pageBlock title="General Information" mode="edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection columns="2"> <apex:inputField required="true" value="{!Proj__c.Name}"/> <apex:inputField required="true" value="{!Proj__c.Expense_Budget__c}"/> <apex:inputField required="true" value="{!Proj__c.Billable_hours__c}"/> <apex:inputField required="true" value="{!Proj__c.Location__c}"/> <apex:actionRegion>  <apex:inputField value="{!Proj__c.Status__c}" id="values"> <apex:actionSupport event="onchange" reRender="newvalue" /> </apex:inputField> </apex:actionRegion>  <apex:outputpanel id="newvalue" > <apex:outputpanel rendered="{!Proj__c.Status__c == '--Other--'}"> <div style="position:relative;left:75px;"> <apex:outputlabel value="new value" for="newval1"/> <apex:inputText value="{!Proj__c.Status__c}" id="newval1"/> </div> </apex:outputpanel> </apex:outputpanel> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
This was selected as the best answer
kmorf_entransformkmorf_entransform

Thanks alot. that worked, but i was wondering why we had to add the actionRegion tag.