+ Start a Discussion

Custom Lookup with dynamic rows added


I am working on Custom lookup added multi rows when I clicked on "ADD" button.

I am able to work for first row, because I am assigning the value in javascript based on VF element Id.

But I need to do the same for multi lines, then finally for all the rows I need to collect the list of data to do DML.

Below are the sample I have written, but not able to complete the rest.

Please suggest me / send me your thoughts to do it.


<apex:page controller="MultiLineCls" cache="true" id="pg">
        function showpopup123(){
           var value1=window.showModalDialog('/apex/page2', '','dialogHeight=800px;dialogWidth=800px');
          return false;
  <apex:form id="fm">
           <apex:repeat value="{!lstC}" var="c">
              <tr><td><apex:inputtext value="{!c.lastName}" id="name"/></td><td>
                  <apex:commandLink >
                              <img src="/s.gif" alt="Parent Account Lookup (New Window)" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className =
    'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="Parent Account Lookup (New Window)" onclick="return showpopup123();"/>
      <apex:commandButton value="ADD" action="{!doADD}" rerender="fm"/>

Controller for the above Page:

public class MultiLineCls{
    public List<Contact> lstC{get;set;}
    public String lkupVal{get;set;}
    public MultiLineCls(){
        lstC = new List<Contact>();
        lstC.add(new Contact());
    public pagereference doADD(){
        lstC.add(new Contact());
        return null;

Lookup Page (page2)

<apex:page controller="GetAccounts" wizard="true">
        function sendacc(accName,accId)
            window.returnValue = accName+"#"+accId;
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a">
                <apex:column headerValue="Account">
                    <a value="{!a.name}" onclick="sendacc('{!a.name}','{!a.Id}')">{!a.name}</a>

Thank you.
Ankit AroraAnkit Arora
You can use wrapper class for this. When you click on "Add" button, new instance of wrapper should be created in your controller which will keep the values for each row separate.