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
Brandon Bridges 16Brandon Bridges 16 

With changing order, How do I dynamically add inputfields to a visualforce page?

I have a visualforce page to be used by customer service consultants. 

Currently, the visualforce page pseudo-dynamically renders inputfield choices through a series of if/then statements that change each field's "renderVariable" to true or false.

So, user picks 'A' from picklist one. Fields A1,A2,A3 appear for input.

Then, user picks 'B' from picklist two. Fields B1,B2 appear for input.

Is there a better way to do this?

The main problem I have is that multiple selections cause multiple fields to render in the order they were entered rather than added to the bottom of the list. Is there a way to make the inputfields append what's already rendered?

<apex:inputField value="{!case.Status}">
  <apex:actionSupport event="onchange" action="{!Evaluate}" rerender="RequiredFields"/>
</apex:inputField>

<apex:pageBlockSection title="Required Fields" id="RequiredFields">
  <apex:inputField value="{!Case.Transaction_Number__c}" label="Transaction Number" rendered="{!if(TransactionNumber==true,true,false)}"/>

----------------------------------------------
public class FieldManager{  
  public case myCase {get;set;}
  public boolean TransactionNumber {get;set;}

  public ShowFieldManager(){
        string PageId=ApexPages.currentPage().getParameters().get('id');
        myCase=[SELECT id FROM case WHERE id=:PageId];        
        
        Evaluate();            
    }

public pagereference Falsify(){TransactionNumber=false;return null;}

public pagereference Evaluate(){
    Falsify();
     if(myCase.status=='Waiting for Transaction Number') TransactionNumber=true;
    return null.
    }
}
Abhilash Mishra 13Abhilash Mishra 13
Hi,
According to me to best way in this situation will be use of fields sets. It allows you to create grouping of different fields.
Like For situaltion  when user picks A, you can create a fieldset that groups fields A1, A2, A3, and A4,  when user picks B, you can create a fieldset that groups fields A1, B1, B2, and B3.
All  you have to do is Query the approriate Fieldset according to the Value Picked by user. and let the dynamic Binding do its Job.
dynamic Binding will allow to render only those fields that are grouped in the fieldset. 

Here are some links To implement dynamic binding with fieldsets.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_dynamic_vf_field_sets.htm 

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_fieldsets_describe.htm\

Let me know if you need more help :)
Good luck ;)

-Abhilash
Brandon Bridges 16Brandon Bridges 16
That sounds like a great idea. Is it possible for one field to be in multiple field sets but only appear one time on the page?
Abhilash Mishra 13Abhilash Mishra 13
Yes It is very much possible. if you will implement them using dynamic Bindings.
if you face any dificulty let me know.
 
 
Brandon Bridges 16Brandon Bridges 16
I'll take a look and get back to you. Thanks for you time!
Abhilash Mishra 13Abhilash Mishra 13
Good Luck :)
you can also contact me on abhilash.udit@gmail.com directly.