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
dfiredfire 

input fields repeater

I have a related list for student (master-detail) of educational institutions the student has previously attended.

 

Since this list will vary for student to student, I would like to create some sort of repeater that will create a new line of fields that will be entered as new record in the related list.

 

The examples I saw using <apex:repeat> seem to just be to display a list of fields for one record, but not a repetition of the same fields for multiple records.

 

So, anybody know how I can do this?

 

thanks.

Best Answer chosen by Admin (Salesforce Developers) 
WesNolte__cWesNolte__c

So you'd still use a repeat and it would run over empty object variables e.g.

 

1. A button called "Add Info" on the page that would call a method "Add()" and reRender the <apex:repeat> component (wrap the repeat in an outputPanel and rerender that for best results).

2. The Add() method would do something like:

 

public PageReference add(){

  Record__c r = new Record__c();

  records.add(r);

  return null;

}

 

3. The records variable would be a publicly accessbile list of the same record type e.g.

public List<Record__c> records{get;set;} // initialise this in the controller constructor to avoid errors records = new List<Record__c>();

4. The repeat would then run over the "records" which wouldn't yet be written to the database but would be storing information for later.

5. A "save" button that does calls an action method that does something like "insert records;"

 

Understand?

 

Wes

All Answers

WesNolte__cWesNolte__c

Hey,

 

A repeat does exactly what you'd like to do. It iterates over a list of records (or classes) and displays the fields value for each record. You might also want to look at <apex:pageblocktable> and <apex:datatable> since they do a similar thing but format the output into neat tables.

 

If you click this link: http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content%2Fpages_compref.htm|SkinName=webhelp

 

And look for "Standard Component Reference" on the left-hand pane you'll find the documentation and examples for each.

 

Wes

dfiredfire

I looked at the reference. But all the examples with <apex:repeat> seem to be where you want to iterate over existing records. I want to create new records.

 

For example, I want the user to submit a list of there past education where each school he attended would be a new record.

 

So line 1 would be: [NAME OF SCHOOL] [START DATE] [END DATE] [GRADUATED] [MAJOR/MINOR]

line 2 would be the next school: [NAME OF SCHOOL] [START DATE] [END DATE] [GRADUATED] [MAJOR/MINOR]

line 3: [NAME OF SCHOOL] [START DATE] [END DATE] [GRADUATED] [MAJOR/MINOR]

and so on...

 

There would be 1 or a few lines showing initially and an option to add more. Obviously we only want to save records with information in them.

 

Does this make sense?

WesNolte__cWesNolte__c

So you'd still use a repeat and it would run over empty object variables e.g.

 

1. A button called "Add Info" on the page that would call a method "Add()" and reRender the <apex:repeat> component (wrap the repeat in an outputPanel and rerender that for best results).

2. The Add() method would do something like:

 

public PageReference add(){

  Record__c r = new Record__c();

  records.add(r);

  return null;

}

 

3. The records variable would be a publicly accessbile list of the same record type e.g.

public List<Record__c> records{get;set;} // initialise this in the controller constructor to avoid errors records = new List<Record__c>();

4. The repeat would then run over the "records" which wouldn't yet be written to the database but would be storing information for later.

5. A "save" button that does calls an action method that does something like "insert records;"

 

Understand?

 

Wes

This was selected as the best answer
dfiredfire
yes, that makes sense. I'll give it a try. Thanks for your help Wes.