You need to sign in to do that
Don't have an account?
Repeat a form in a vf page
hello, i looked in-depth on how to use a vf as the following picture shows:
-----------------
Delivery:
Delivery name:
Delivery status:
-----------------
+Add a new product
(each time i click of +Add a new product -->)
--------------------------
Product type:
Product name:
-------------------------
Use case: Deliver multiple products on each delivery for one client, the sf administrator will add a new delivery, each delivery might have different type of products but sticked to the same delivery, so how to include a function to add a new product for this delivery, each time i click on this button, a new div will appear loading the product info to fill.
I undrstan that i need to add custom objects and custom controllers, but i dont see how to make the add a new product happen, dynamically. Is there any document or function to rely on?
This can go to nth level, as you are writing the custom code.
You need to do : Onclick of the delivery opens a div and use action function to save the new product for the delivery.
I think using a wrapper class will make things much simpler, unlike javascript.
This can be done through <apex:repeat/>
create a property in your controller for listofProducts,
public List<Product__c> lstProducts{get;set;}
and in Add product action do this,
public void AddProduct()
{
lstProducts.add(new Product__c(include all the required fields also fields used in page and assign blank or null values));
}
Then in page loop this list using the <apex:repeat/> tag:
<apex:repeat value="{!lstProducts}" var="p">
Product Type : <apex:inputText value="{!p.ProductType__c}"/>
Product Name : <apex:inputText value="{!p.ProductName__c}"/>
</apex:repeat>
use table in the repeat for correct alignment.
Hope this helps.
Regards,
Shravan
Use the Action method Add whenever the user click on the "ADD A PRODUCT " button or Link. which sets the value of a flag variable as TRUE. The command buttton as
<apex:commandButton action="{!add}" value="Add A Product"/>
Below the button define a pageblock as
<apex:pageBlock rendered="{!flag}">
Product type: <apex:inputText value="{!a}"/>
Product name:<apex:inputText value="{!b}"/>
<br/>
<apex:commandButton action="{!addproduct}" value="Add"/>
</apex:pageBlock>
Whenever the user will click the button Add A Product , value of the flag will turn TRUE and the PageBlock will be rendered. Variables a and b are input text that can be added to particular products details inside the addproduct method.
To make sure that the pageblock is not displayed when you add particular product, set the value of the flag variable as false inside addproduct action method.
Hope this method will work.