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
vineet_mvineet_m 

Add Another row for child Object

I want to create a page, just to ease the users' effort. Here two objects are used Project__c(Parent) Project_Hour__c(Child) having lookup relationship between them. Fields(project Name, Total Hour Allocated & Total Hour spent) are being fetched from the parent object i.e. Project__c and other fields like (Hour type, Hours & Short Description) are coming from the child object Project_Hour__c.

 

In the page, all those projects are shown which are related to the currently logged- in User and an user at any point of time may insert or delete any number Project_Hour__c. so In order to add more i have added a '+' button overhere in the page, this will be appending/ addding another row for new record and similarly the '-' minus button shall be deleting the current record.

 

I have made use of two repeats, and when i click on Plus '+' button, it leads to addition of a new row, but at the end not exactly where it has been clicked.

 

Please clue/ tip me. Need the row to come exactly beneath where the plus '+' button has been clicked ASAP.

 

P.S. -- Below is the image.

 

 

 

Thanks

Vineet M

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet as reference:

 

<apex:page controller="Dynamictextbox">
<apex:form >
<apex:outputPanel id="op1">
<apex:commandButton value="+" action="{!show}" reRender="op1"/>
<table>
<apex:repeat value="{!mainlist}" var="m">
<tr><td><apex:inputText value="{!m.name}"/></td></tr>
</apex:repeat>
</table>
<apex:commandButton value="FinalData" action="{!finalmethod}" reRender="op2"/>
</apex:outputPanel>
<apex:outputPanel id="op2">
<apex:repeat value="{!fianllist}" var="f1">
{!f1}
</apex:repeat>
</apex:outputPanel>

</apex:form>
</apex:page>
===================Apex Controller===============
public class Dynamictextbox
{
integer i = 0;
public list<string> fianllist{get;set;}
public class test
{
public String name{get;set;}
}
public list<test> mainlist{get;set;}
public Dynamictextbox()
{
mainlist = new list<test>();
test t1 = new test();
t1.name='NavatarGroup'+i;
mainlist.add(t1);
i++;
}
public void show()
{
test t1 = new test();
t1.name='NavatarGroup'+i;
mainlist.add(t1);
i++;
}
public void finalmethod()
{
fianllist = new list<String>();
for(test t2:mainlist)
{
fianllist.add(String.Valueof(t2.name));
}
}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.