0

Scenario

I must Collect 40+ fields worth of information on an visualforce form. This must be broken up on multiple pages instead of one long page.

Story So Far and Research

The form dynamically populates input fields based on the contents of a fieldset This is done using < apex:repeat >

Learned from: http://www.sfdcpoint.com/salesforce/fieldset-visualforce-page-salesforce/

And the associated controller queries the fields in that field set based on the requested account record. Adapted from this accept to pull only a specified field set’s instead of all fields:

http://www.sfdcpoint.com/salesforce/dynamic-soql-query-fetch-fields-object-salesforce/

Problem

I would like to break the 40+ fields in into multiple field sets. Each fieldset represents a page of the form. Once a user has filled out a page of fields they hit save and move to the next page. But instead of moving to a new page; the page re-renders to the next fieldset until All the fields sets have been iterated through.

How can I re-render a visualforce form to collect different fields ?

(My thought is too have an global list of field sets that iterates through in my save function.)

excert from VF Page

<apex:repeat value="{!$ObjectType.Account.fieldsets.Master_Application_Field_Set}" var="fieldValue">
        <apex:outputLabel value="{!fieldValue.FieldPath}"/>
        <apex:Inputfield value="{!Account[fieldValue]}"/>
</apex:repeat>
2

You can put the field sets into different output panels (apex:outputPanel) and then conditionally render them as needed.

For example:

<apex:outputPanel layout="block" rendered="{!showFirstPanel}">
    <apex:repeat value="{!$ObjectType.Account.fieldsets.Field_Set_Initial}" var="fieldValue">
        <apex:outputLabel value="{!fieldValue.FieldPath}"/>
        <apex:inputField value="{!account[fieldValue]}"/>
    </apex:repeat>
</apex:outputPanel>

<apex:outputPanel layout="block" rendered="{!showSecondPanel}">
    <apex:repeat value="{!$ObjectType.Account.fieldsets.Field_Set_Secondary}" var="fieldValue">
        <apex:outputLabel value="{!fieldValue.FieldPath}"/>
        <apex:inputField value="{!account[fieldValue]}"/>
    </apex:repeat>
</apex:outputPanel>

Then in your controller you will need to do any validation (if needed) and if that is successful turn the previous panel off and turn the next panel on. If you put all of your output panels into one apex:form you can target the form for rerender which will re-evaluate all of the output panels only displaying the ones that you have set to true in your controller. This implementation would also allow you to have a "back" button to go back to a previous section of the form if the user needs to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.