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
tengeltengel 

Autofill date fields based upon first date field selection

Hello! I am overriding the standard Opportunity Product selection page. I have two custom fields, Effective Date and Expiration Date, on this page. My users would shower me with gifts and praise if I could implement functionality that would auto-populate all Product Effective and Expiration Date fields based upon the selection they make in the first Product row (see this image for clarification).

 

I know this will require Javascript, which I know next to nothing about. Hopefully, since I am already overriding the page with Visualforce, someone can provide a Javascript code snippet that I can easily paste in to at least get started? Thanks for any help!

 

 

AppyAppy

Here is a workaround to achieve similar functionality. 
You can have a button or a link which on being clicked copies the value in a particular input text box to other specified text-boxes. So rather than repeatedly entering the data, the user can populate all the fields at the click of a button. 

Images here 
Link1

Link2

VF page code 

 

<apex:page controller="autofill_fields" >
<apex:form >
<apex:pageBlock >
<apex:outputText >Auto-fill input 2 to input 4 based on value entered in input 1</apex:outputText>
<p></p>
<apex:pageBlockSection columns="1">
<apex:inputText label="Input1" id="in1" value="{!val1}"/>
<apex:inputText label="Input2" value="{!val2}" />
<apex:inputText label="Input3" value="{!val2}"/>
<apex:inputText label="Input4" value="{!val2}"/>
<apex:commandButton value="Fill" action="{!method1}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>


Apex code

public class autofill_fields {

public string val1 {get; set;}
public string val2 {get; set;}


public pagereference method1()
{
if (val1 != null)
{
val2 = val1;
}
return null;

}

}



 

Jerun JoseJerun Jose
As you guessed, this should be possible using javascript but it would be a little complex to achieve this one.
Instead what I would suggest is to use an actionfunction.

The visualforce tag apex: actionfunction is the VF intermediate for Javascript. You can use that to have a javascript function that will call an apex method.

So, on the VF page, you can have an actionfunction, and call this actionfunction onchange of the date input fields.
The actionfunction will inturn call an apex method, where you can populate the values for the date fields.
Your actionfunction can use a rerender which will repaint the table with the values defaulted by the controller.