+ Start a Discussion
Nick KaldenbergNick Kaldenberg 

Changing What input fields are visible and required based on user input.

I have a VF page for new requests for sales support.  They choose what kind of request it is from a picklist. New Product, Pricing, Reports, ETC. Each of these have a set of minimum required information for us to complete the request.  Can I use an IF statement that will set the visibility and required status of the input object based on the input of that initial picklist value? or is there an easier way to do this?  I am fairly new to salesforce and visualforce coming from working with MS Access and sharepoints. 
Best Answer chosen by Nick Kaldenberg
ForceMantis (Amit Jain)ForceMantis (Amit Jain)
Yes you can do it, if you have basic working knowledge of VF pages you will be able to setup this.

You need to add an apex:actionsupport with you controlling picklist.
You need to put all other controls in a container like apex:outputpanel and have a Id parameter set for this.
In Action support you have to use rerender with id of outputpanel created above
Then you need to use rendered and required attributes with each control and have if condition using VF expression syntax to conditionally require/show controls.

All Answers

ForceMantis (Amit Jain)ForceMantis (Amit Jain)
Yes you can do it, if you have basic working knowledge of VF pages you will be able to setup this.

You need to add an apex:actionsupport with you controlling picklist.
You need to put all other controls in a container like apex:outputpanel and have a Id parameter set for this.
In Action support you have to use rerender with id of outputpanel created above
Then you need to use rendered and required attributes with each control and have if condition using VF expression syntax to conditionally require/show controls.
This was selected as the best answer
Nick KaldenbergNick Kaldenberg
I have tried doing this but cannot get it to rerender.  I believe the mistake is somewhere with the actionsupport.  Here is a copy of the code for this section please let me know if you see any obvious errors. Thanks!
<apex:outputpanel id="NPI">
        <apex:pageblocksection title="Required Information" columns="2">  
        <apex:inputfield value="{!request.Request_Type__c}" required="true"/>
            <apex:actionsupport event="onchange"
                    rerender="NPI" />
            <apex:inputfield value="{!request.date_to_complete__c}" rendered= 
                "if(!request.request_type__c = 'NPI',true,false)"/>
            <apex:inputfield value="{!request.Product_SKU__c}"/>
            <apex:inputfield value="{!request.product_description__c}"/>
            <apex:inputfield value="{!request.Meet_Comp_Needed__c}"/>
            <apex:inputfield value="{!request.pricing__c}"/>
            <apex:inputfield value="{!request.data_sheet__c}"/>
            <apex:inputfield value="{!request.setup_sheet__c}"/>
            <apex:inputfield value="{!request.images__c}"/>
            <apex:inputfield value="{!request.setup_in_system__c}"/>
            <apex:inputfield value="{!request.setup_under__c}"/>
            <apex:inputtextarea value="{!request.Request_Information__c}" styleclass="info" required="true" />
        </apex:pageblocksection>
        </apex:outputpanel>



Nick KaldenbergNick Kaldenberg
Thank you ForceMantis for your help.  with what you gave me as a starting point and some more research I was able to accomplish my goal.  i ended up having to use actionregion along with the actionsupport and used it to rerender whole output panels set up for each request type instead of individual controls.
ForceMantis (Amit Jain)ForceMantis (Amit Jain)
I am glad to hear that it helped you.