3

In our Visualforce page we need a date picker which must bind to some local variable in our controller(not sObject variable).

So we used the following code

<apex:inputText id="selected_date" onclick="DatePicker.pickDate(true, this, false);"  
                                    value="{!selectedDate}" size="10" style="width:70px;"/>

But when I click the input box it shows 2 javascript errors.

Uncaught TypeError: Cannot read property 'addEventListener' of null
Uncaught TypeError: Cannot read property 'currentStyle' of null

After googled the error I got this link. This link suggest the workaround as change the VF API version to 29.0 or lower.

This seems temporary solution. Why they removed this option in newer APIs ? Is there any better solution available ?

  • Can you try this.. I think you need to specify size="10" <apex:inputText id="selected_date" onclick="DatePicker.pickDate(true, this, false);" value="{!selectedDate}" size="10"/> – Ratan Paul Mar 8 '16 at 12:52
  • @Ratan I tried that also – SANN3 Mar 8 '16 at 12:54
  • So if you change your page API to 29 or lower then It work or not? If this work then report this issue – Ratan Paul Mar 8 '16 at 12:57
  • @Ratan after change API to 29 it is working. But it is not a proper solution right. – SANN3 Mar 8 '16 at 13:05
  • 2
    SANN3 If this is the case then report this issue to salesforce. This is not code issue.. and wait for other response may be they have any solution.. – Ratan Paul Mar 8 '16 at 13:07
2

One thing to make sure if you are using classic date picker is, don't set StandardStyleSheet="false" in the page.

| improve this answer | |
1

I created a dummy sObject and added a date field and used in my VF page. It is working without any issue.

| improve this answer | |
0

This is happening because salesforce is not loading the required js file for displaying the date picker. You can avoid this issue by adding a dummy date field (hide it using display: none;) in the visualforce page so that Salesforce will load all the required js files for displaying the default date picker.

Update code will be like this

<apex:inputText id="selected_date" onclick="DatePicker.pickDate(true, this, false);"  
                value="{!selectedDate}" size="10" style="width:70px;"/>

<div style="display:none;">
    <apex:inputField value="anyObject.AnyDateField__c" /> 
</div>
| improve this answer | |
0

Solution is change the tag from apex:inputText to apex:input with type="date"

Before:

<apex:inputText id="selected_date" onclick="DatePicker.pickDate(true, this, false);" value="{!selectedDate}" size="10" style="width:70px;"/>

After:

<apex:input type="date" id="selected_date" value="{!selectedDate}" size="10" />

Reference:

https://developer.salesforce.com/forums/?id=906F0000000kGxpIAE

| improve this answer | |
-1

type="text" and showDatePicker="false"attributes helped in my case.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.