Date Picker limitation problem in visualforce page(Salesforce) [Solved]

Feedback

If you have been in force.com and salesforce development then probably you might encountered a problem where you have face a challenge that you could not able to pick the date beyond certain limit , today developing a visualforce page i could not able to pick a date from the date field beyond a certain limit example(2 years back) that is something not that much flexible for the people who want to select his or her birth date need then to enter there birth date they have to enter the value manually instead of picking the value from the date picker, you can see the below picture that salesforce data picker show limited values in date field.

Date pick limitation in salesforce

As you can see in the below image that we have limit for date pick in salesforce but we can overcome to this problem by using a simple JavaScript which would give flexibility to developer to add range of years in date picker.

date picker problem in salesforce

Solution to extend date pick range

See below java script and most important check 4rth and 5th line to customize the script.

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></apex:includeScript> 
<span id="hideMyParent"></span> 
<script type="text/javascript"> $(document).ready(function() { 
var startYear=1930; 
var endYear=2000; 
var optionsString=''; 
if(startYear<endYear){
 for(i=startYear;i<endYear+1;i++){ 
optionsString += "<option value=\""+i+"\">"+i+"</option>"; 
}
$('#calYearPicker').html(optionsString); } $('#sidebarDiv #hideMyParent').parent().parent().hide(); });
</script>

Copy above script and paste it in your visualforce page below apex:page tag and then save your visualforce page ,see below image now how your visualforce page would going to be look like

solved datepick problem

This is the just a small script i hope your problem is now get solved if you have any problem in using do tell me i will loved to help you and also don’t forget to subscribe to my blog and my social networking pages.

Note
1.) Don’t forget to include jquery in your visualforce page.
2.) Always include HTTP instead of HTTPS while including the jquery.
3.)Don;t add any comment in javascript because salesforce will convert above code into a singular line code so if any comment found rest after that every will get commented.

Related Articles :

Speak Your Mind

*