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
carmantcarmant 

Stop date field auto-populating

Hi,

 

I am making a simple VF page with some date fields.

 

There is also a javascript to gray out boxes depending on which radio button is selected.

 

However, how can I stop the date fields from being autopopulated with the current date and time? I want them to be blank by default.

 

Date Fields

 

Here is the code:

 

<!-- Define controller, create main page block and first section -->
<apex:page controller="dashboardRadio">
<apex:PageBlock title="Dashboard">
<apex:pageBlockSection title="Select Type of Update" columns="1">

<!-- Java script to gray out n/a boxes -->
<script type="text/javascript"> function getActive(selectedValue) 
     {
        if( selectedValue == 'noDate') 
           { 
          var ele=document.getElementById('{!$Component.form1.startDate}');
              ele.disabled =true;
          var ele=document.getElementById('{!$Component.form1.endDate}');
              ele.disabled =true;
           }
        else if(selectedValue == 'oneDate')   
           {
           var ele=document.getElementById('{!$Component.form1.startDate}');
               ele.disabled =true;
           var ele=document.getElementById('{!$Component.form1.endDate}');
               ele.disabled =false;
           }
        else if(selectedValue == 'twoDate')
           {
           var ele=document.getElementById('{!$Component.form1.startDate}');
               ele.disabled =false;
           var ele=document.getElementById('{!$Component.form1.endDate}');
               ele.disabled =false;
           }
    }       
</script>

<style>
    .dateFormat{display:none;}
</style>



<apex:form id="form1">
<apex:selectRadio value="{!selectedValue}" layout="pageDirection" onchange="getActive(this.value);">
        <apex:selectOption itemValue="noDate" itemLabel="No date & time"/>
        <apex:selectOption itemValue="oneDate" itemLabel="Single date & time"/>
        <apex:selectOption itemValue="twoDate" itemLabel="Date & time span"/>
            </apex:selectRadio><p/>

        
      Start Date  <apex:inputField value="{!c.dashboard_start_date__c}" id="startDate" required="false"/><br></br>
    End Date  <apex:inputField value="{!c.dashboard_end_date__c}" id="endDate" required="false"/><br></br>
</apex:Form>
</apex:PageBlockSection>

</apex:PageBlock>        
</apex:page>
 

 

 

 

Thanks!

 

 

 

 

carmantcarmant

Anyone got any ideas on this? Still stuck with it!

Starz26Starz26

Are you sure that in the field definition you do not have a default value set?

 

In my prod org and my dev org, using a standard controller and binding to a DT field value="{!account.dtfield__c}" does not cause it to autopopulate.

 

I also am showing the quick entry on the page which I do not see on your page so that makes me curious

madhu_ramadhu_ra
I know that this is an older post but thought sharing my resolution for the same issue so that it will benefit someone else in the cloud.

Just initialize your 'c' variable in controller constructor.
 
c = new MyCustomObj__c();