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
The KnightThe Knight 

How to avoid datepicker pop up on load of the visualforce page

Hi,
    I am using custom field of type date in my visualforce page as inputfield.  the code is like this
<apex:pageBlockSection title="Choose Date Range to generate Reports">
<apex:inputField id="fromdate" value="{!fromDateTask.From_Date__c}" id="fromdate"/><br/>
<apex:inputField id="todate" value="{!toDateTask.To_Date__c}" id="todate"/><br/>
</apex:pageBlockSection>.
   when ever the page is getting loaded the datepicker pop's up from the "fromdate" inputfield.  The datepicker should popup only when we click on it. How to avoid the popup onload event.
 
Thanks,
Joseph
Ron HessRon Hess
is there another field you can place the focus on?

if not, you can override the default behavior that places the focus on this (date) input field.
The KnightThe Knight
Hi Ron,
   There are only two (date) input fields in that page. you said that we can override the default behavior that places the focus on this (date) input field. could you please let me know how to do that. 
 
Thanks,
Joseph
Ron HessRon Hess
Sure, please understand that this is not a supported api, but the process of setting the focus occurs after page load

try something like this
Code:
<script >
//Attempt to override JavaScript that is setting focus on Date field
function setFocusOnLoad() {}
//Or use beenFocused = true; </script>

 
Please post an idea on the idea exchange for a proper way to avoid focus on a date widget at body loaded time


The KnightThe Knight
Thanks Ron I have just overrided the onfocus event as you said.
reidjnreidjn

Ron, 

 

Is this still not available?

Anna ProvizAnna Proviz

Just Set the focus on another field , like this:

 

<input id="hiddenElementId" type="hidden" />
<script type="text/javascript">
window.onload = setFocus
function setFocus()

{
         document.getElementById("hiddenElementId").focus();
}
</script>

Sean RussellSean Russell
You should be careful with this solution as it will break any input elements you have with hover text. The reason is because, in the solution above, you are redefining the windlow.onload function. The salesforce libraries rely on that to set up elements on the page. A better way would be to redefine just the setFocus method as such:

<script type="text/javascript">
function setFocus() { }
</script>