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
VarunCVarunC 

custom datepicker component

Hi,

here is my code for a Custom Component which i'm creating for inserting a DatePicker Control in VF page:
Code:
<apex:component >
 <apex:attribute name="pickDateLabel" description="This is the value for the label to display before pickdate component." type="String" required="true"/>
 <apex:attribute name="pickDateField" description="This is ID value of the Field to be used for component." type="String" required="true"/>
 <apex:attribute name="defaultValue" description="This is value of the Field." type="String" required="false"/>
 
 <SCRIPT src="{!URLFOR($Resource.jQuery_UI_DatePicker,'/ui.datepicker/jquery-1.2.6.min.js')}" type="text/javascript" />
 <apex:stylesheet value="{!URLFOR($Resource.jQuery_UI_DatePicker,'/ui.datepicker/smoothness/ui.datepicker.css')}" />
 <SCRIPT src="{!URLFOR($Resource.jQuery_UI_DatePicker,'/ui.datepicker/ui.datepicker.js')}" type="text/javascript" />

 <span style="font-weight:bold;text-align:right;">{!pickDateLabel}:&nbsp;</span>
 <input name="{!pickDateField}" id="{!pickDateField}" value="{!defaultValue}" style="font-size:12px;width:80px;" />
 <apex:inputText id="datePicker" value="{!defaultValue}" style="font-size:12px;width:80px;"></apex:inputText>

 <script type="text/javascript">
  $(document).ready(function(){
   $("#{!pickDateField}").datepicker({ 
       showOn: "both", 
       buttonImage: "{!URLFOR($Resource.jQuery_UI_DatePicker,'/calendar.dp.png')}", 
       buttonImageOnly: true,
       buttonText: "Pick date",
       dateFormat: 'mm/dd/yy'
   });
   $("#{!$Component.datePicker}").datepicker({ 
       showOn: "both", 
       buttonImage: "{!URLFOR($Resource.jQuery_UI_DatePicker,'/calendar.dp.png')}", 
       buttonImageOnly: true,
       buttonText: "Pick date",
       dateFormat: 'mm/dd/yy'
   });
  });
 </script>
 
</apex:component>

 
I use it in VF page using this:
Code:
<c:jQueryPickDate pickDateLabel="From" pickDateField="frmDate" defaultValue="{!frmDate}" />

 
Now, there are 2 textboxes shown on VF page where i use the Component, 1st One is Simple HTMl control, and is very nicely parsed by jQuery and a Date pick Calendar is shown on the Image lying adjacent to first textbox.

The 2nd one is Apex:InpuetTExt control, and is Not parsed by jQuery, and the Calendar is not shown for this control.

This is the HTML shown in Firefox on VF page load:
Code:
<span id="thePage:theForm:pageBlockFilter:j_id8">
 <script type="text/javascript" src="/resource/1228293028000/jQuery_UI_DatePicker/ui.datepicker/jquery-1.2.6.min.js"/>
 <script type="text/javascript" src="/resource/1228293028000/jQuery_UI_DatePicker/ui.datepicker/ui.datepicker.js"/>

 <span style="font-weight: bold; text-align: right;">From: </span>
 <input value="" style="font-size: 12px; width: 80px;" name="frmDate" id="frmDate" class="hasDatepicker"/><img align="absbottom" class="ui-datepicker-trigger" src="/resource/1228293028000/jQuery_UI_DatePicker/calendar.dp.png" alt="Pick date" title="Pick date"/>
 <input type="text" style="font-size: 12px; width: 80px;" name="thePage:theForm:pageBlockFilter:j_id8:j_id9:datePicker" id="thePage:theForm:pageBlockFilter:j_id8:j_id9:datePicker"/>

 <script type="text/javascript">
  $(document).ready(function(){
   $("#frmDate").datepicker({ 
       showOn: "both", 
       buttonImage: "/resource/1228293028000/jQuery_UI_DatePicker/calendar.dp.png", 
       buttonImageOnly: true,
       buttonText: "Pick date",
       dateFormat: 'mm/dd/yy'
   });
   $("#thePage:theForm:pageBlockFilter:j_id8:j_id9:datePicker").datepicker({ 
       showOn: "both", 
       buttonImage: "/resource/1228293028000/jQuery_UI_DatePicker/calendar.dp.png", 
       buttonImageOnly: true,
       buttonText: "Pick date",
       dateFormat: 'mm/dd/yy'
   });
  });
 </script>
 
</span>

 
Just check that ID passed in jQuery Javascript function is CORRECT one and still no Calendar associated with i2nd textbox :(.

please help.
IndeevarIndeevar

Hi Vishal

Where do download the jQuery_UI_DatePicker.js file from??

VarunCVarunC
It is a Static Resouce containing jQuery Datepicker library .... you need to download the library fioles from www.jquery.com .... and upload it as static resource in Salesforce.
IndeevarIndeevar

HI Vishal

We are having issues in loading the DatePicker. Couiple of queries here.

We just used used your component and contoller class AS-IS and updated the resource locations for JS and CSS files. Copied all the  3 JS files and 1 CSS file into static resource.

--> In theVF page we are just calling controller as per you mentioned. Are we missing something here?

--> Also will this DatePicker Component work only for HTML text control Or for both HTML and <Apex:inputtext> as well?

 

Please help on this.

VarunCVarunC

One Correction .. its Varun not Vishal :)

 

and please check back here .. this is the working set, it includes sample code too:

http://wiki.developerforce.com/index.php/Code_Samples#jQuery_DatePicker_Component_for_Selecting_Date_in_VisualForce_Page

 

 

here is the transcript from the above link:

jQuery DatePicker Component for Selecting Date in VisualForce Page This Component When used will place a TextInput with a calendar icon adjacent to the input control, so as to Popup a Calendar and have selected Date inserted in the input control, just like the Date Control of Salesforce, which is currently Bounded to be Used only with Data Bounded Fields. So this way, you simple place a call like: <c:jQueryPickDate pickDateLabel="Pick Date:" pickDateField="selectDate" value="{!selectedDate}" /> And you will have a Date Control on you VisualForce page. This control is created using jQuery's DatePicker plugin. Click Here For Component Code -Varun Chaddha, Advologix.com

 

This thread is for the Error I was facing so the CODE posted in first message at TOP is Not working at all .. so you might not be able to get it working ...

Please check the code at the Link I just provided you .. and check the attached sample in the link works for you ro not ....

IndeevarIndeevar

Hi Varun

 

 Thanks for the response Varun ( this time I got it right)..

Actually I have downlaoded from that link only. So u mean to say if we want to make this component work

we dont have to change anything except for Resource locations in component is it?

 

VarunCVarunC

You can change the code .. if you are familiar with jQuery customizations .. but if your requirement is fullfilled with this code then I would suggest not to make changes as this was a working set i uploaded :) ...

 

there were issues with inputtext control and html controls .. though If I'm not wrong then I do use Inputtext control ... in the component ...

 

just to Clarify where you MIGHT end up stuck .. if you are refering any INPUTTEXT control using jQuery then you Might not be able to do so .. because Salesforce creates ID values for All Controles in this patern:

 

parentid:childid:anotherchildid: ... etc ... NOTE the ":" in the id values ...

 

Now issues I faced was jQuery was NOT able to get the Object using the salesforce generated id values ... contain colon in the control id values.

 

IndeevarIndeevar

Appreciate your help Varun. But somehow your working copy is not working for us.

--> Could you please send calendar.dp.png image file?

--> Also in the component code

 

<apex:inputText styleClass="{!pickDateField}_dtClass" id="datePicker" value="{!value}" style="font-size:12px;width:80px;"></apex:inputText>

 

what does value for the attribute styleClass="{!pickDateField}_dtClass" refer to?

 

Can u send us the screen shot of your component and controller code? Also a screen shot of the browser page where this is being used. Sorry for bugging you. Your help would be highly appreciated. Really getting frustrated for the last 3 days in exploring this functioanlity.

VarunCVarunC

here is how I use the compoenent in VF page ...

<c:jQueryPickDate pickDateLabel="From:" pickDateField="frmDate" value="{!frmDate}" /> <c:jQueryPickDate pickDateLabel="To:" pickDateField="ToDate" value="{!toDate}" />


Indeevar wrote:

what does value for the attribute styleClass="{!pickDateField}_dtClass" refer to?


As i told you i was not able to reference Control using ID value in jQuery .. in visualforce page so I used the jQuery's method to refer controls using StyleClasses ... using CSS ... {!pickDateField} = ID value for the control to be passed as Component Attrobute ....

 

here i the calendar.dp image: Calendar.dp image

 

Here is the Component Code:

<apex:component controller="cmp_jQueryPickDateController"> <apex:attribute name="pickDateLabel" description="This is the value for the label to display before pickdate component." type="String" required="true"></apex:attribute> <apex:attribute name="pickDateField" description="This is ID value of the Field to be used for component." type="String" required="true"></apex:attribute> <apex:attribute name="value" description="" type="String" required="true"></apex:attribute> <script src="{!URLFOR($Resource.jQuery_UI_DatePicker,'/ui.datepicker/jquery-1.2.6.min.js')}" type="text/javascript"></script> <apex:stylesheet value="{!URLFOR($Resource.jQuery_UI_DatePicker,'/ui.datepicker/smoothness/ui.datepicker.css')}"></apex:stylesheet> <script src="{!URLFOR($Resource.jQuery_UI_DatePicker,'/ui.datepicker/ui.datepicker.js')}" type="text/javascript"></script> <span style="font-weight:bold;text-align:right;">{!pickDateLabel}&nbsp;</span> <apex:inputText styleClass="{!pickDateField}_dtClass" id="datePicker" value="{!value}" style="font-size:12px;width:90px;"></apex:inputText> <script type="text/javascript"> $(document).ready(function(){ $(".{!pickDateField}_dtClass").datepicker({ showOn: 'button', buttonImage: "{!URLFOR($Resource.jQuery_UI_DatePicker,'/calendar.dp.png')}", buttonImageOnly: true, buttonText: 'Pick date', dateFormat: 'yy-mm-dd' //'mm/dd/yy' }); }); </script> <style> .{!pickDateField}_dtClass + img { left:-17px; position:relative; top:-1px; } </style> </apex:component>

 

public class cmp_jQueryPickDateController {

}
IndeevarIndeevar
Thanks a bunch Varun. Will try now and get back to you if I face any queries..
IndeevarIndeevar

Hi Varun

Still no luck for us. Any ways seeing your code I am seeing include CSS and JS files under some folders like ui.datepicker and smoothness etc.. Where as we have all the 4 files (3 JS and 1 CSS) files under under the same root in a ZIP file which I added to the static resources. Am I missing some other files here??

 

 <SCRIPT src="{!URLFOR($Resource.DatePicker,'jquery-1.3.2.min.js')}" type="text/javascript" />
<SCRIPT src="{!URLFOR($Resource.DatePicker,'ui.datepicker.js')}" type="text/javascript" />
<SCRIPT src="{!URLFOR($Resource.DatePicker,'ui.core.js')}" type="text/javascript" />
<apex:stylesheet value="{!URLFOR($Resource.DatePicker,'ui.datepicker.css')}" />

 

 

Also your controller class of component is empty. Is that OK??

VarunCVarunC

no it looks ok ... to me ... you need to add Custom CSS style which was added in the COMPONENT itself at bottom .. also ...

 

plus as a good practice which i didn't knew earlier was .. ALWAYS use END tags and Closing tags atleast in Visualforce pages ... sometimes an inline closing tag causes a broken componenet ...

 

so i would now change those script and style tags to:

 

<SCRIPT src="{!URLFOR($Resource.DatePicker,'jquery-1.3.2.min.js')}" type="text/javascript" ></script> <SCRIPT src="{!URLFOR($Resource.DatePicker,'ui.datepicker.js')}" type="text/javascript" ></script> <SCRIPT src="{!URLFOR($Resource.DatePicker,'ui.core.js')}" type="text/javascript"></script> <apex:stylesheet value="{!URLFOR($Resource.DatePicker,'ui.datepicker.css')}"></apex:stylesheet>

 

 

 

the datepicker control of jquery i used was and can be controlled using Themess .. so I used seperate Resources so that in future if new look is needed to be used then i will simply upload a new them as statuc resource and reference the css directly there ...

 

and controller code being empty .. :) .. this component was First one of mine ... so was never sure what comtroller class could be used for I included it byy reading some example and then since there was no values passed from component page to controller .. you can SAFELY remove the controller class ... :)

Message Edited by vchaddha on 03-20-2009 03:49 AM
ShikibuShikibu
vchadda, can you provide a little detail on what/where to download? I visited http://jqueryui.com/docs/Getting_Started, created a custom download, rearranged it to match the directory structure implied by your component code and re-zipped it, but I am still missing calendar.dp.png. Perhaps I am going about it all wrong?
VarunCVarunC

Shikibu wrote:
vchadda, can you provide a little detail on what/where to download? I visited http://jqueryui.com/docs/Getting_Started, created a custom download, rearranged it to match the directory structure implied by your component code and re-zipped it, but I am still missing calendar.dp.png. Perhaps I am going about it all wrong?

You missed the 2nd last post on first page for this thread.

 

I've provided the Link to the Calendar.dp.png file there. here it is again:

 

 

MukulMukul

Hi Varun,

 

I tried downloading the jQuery date picker thats on the wiki. I created a new file in Static Resources - Date_UI_Picker. However it doesnt seem to work.

 

Can you please explain me that how should it work?

 

Regards

Mukul

Vishal GaddiVishal Gaddi

<c:DatePickerExtend startYear="1970" endYear="2030"/>.....

Use this in Visualforce page.... Thts a simple one...

Santosh TripathySantosh Tripathy
Varun need help, in the url https://developer.salesforce.com/page/Code_Samples#jQuery_DatePicker_Component_for_Selecting_Date_in_VisualForce_Page, its not allowing me to download, do i need a google account with access?