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
Brad HuffmanBrad Huffman 

Customizing datepicker

We have a date of birth field on a custom object.  When we bind this field to an apex:inputfield the datepicker has a rather limited range of years in it.  Can we specify a year for it to start with?  Say 30-40 years ago?  I realize that a user could just type a date in, but it inevitably ends up that the user sees the datepicker control and thinks that they need to use it to select a date.  Thanks for any help.
Best Answer chosen by Admin (Salesforce Developers) 
dchasmandchasman
A strong word of caution - the date picker/calendar/etc javascript source is not a published or supported API and as such is subject to change - going to change - over time without notice so do this kind of DOM/js scraping at your own risk. Salesforce.com reserves the right to change any and all internal details like this at any time.

With that safe harbour stuff said my team is well aware of the gap between what we have out there w.r.t. client side component/widget APIs and we are working on providing formal client side component APIs for future releases.


Message Edited by dchasman on 10-04-2008 06:31 AM

All Answers

jeremy_rossjeremy_ross
Sorry for lack of a definitive answer, but I'd try to dig into the calendar's javascript source and see if its api allows you to programatically set the parameters you mention.
David VPDavid VP
You can't specify a year range as far as I know but if you now that the datepicker creates a <select id="calYearPicker" ...> element, you could hack into the DOM a bit :

Code:
 <script type="text/javascript">
          
     function changeYears() {     
         var yearselect = document.getElementById('calYearPicker');
         for(var i=0; i < 30;i++) {
             var elOptNew = document.createElement('option');
                elOptNew.text = 2014 + i;
                elOptNew.value = 2014 + i;
                yearselect.add(elOptNew, null);
         }
     }
 </script>

 
Attach this to some eventlistener ('onfocus' on the field for example) and it will modify the years you have in the option list.
Note : I started on 2014 because right now the datepicker goes to 2013 but that's not very 'Year 2009 compliant' :smileyhappy:
You'll also have to make sure that this script only runs once, and don't forget to check IE/FF compatibility.



Hope this helps,


David
dchasmandchasman
A strong word of caution - the date picker/calendar/etc javascript source is not a published or supported API and as such is subject to change - going to change - over time without notice so do this kind of DOM/js scraping at your own risk. Salesforce.com reserves the right to change any and all internal details like this at any time.

With that safe harbour stuff said my team is well aware of the gap between what we have out there w.r.t. client side component/widget APIs and we are working on providing formal client side component APIs for future releases.


Message Edited by dchasman on 10-04-2008 06:31 AM
This was selected as the best answer
David VPDavid VP
Good to hear about the client side component API ! Thanks for letting us know.

(and I'll make sure to tell people when going outside of the supported API  :smileywink:  )


David

Brad HuffmanBrad Huffman
All excellent bits of info.  Thanks for the replies.