You need to sign in to do that
Don't have an account?
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. } }
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
if you face any dificulty let me know.
you can also contact me on abhilash.udit@gmail.com directly.