10

I want to use a date picker but what I am getting is a normal text field to add/edit date how can I bind a date picker?

<apex:inputText rendered="{!fieldType='DATE'}" value="{!valueToUpdate}" />
1
  • 3
    You need to use apex:inputField instead and bind it with a date field. Commented Oct 10, 2013 at 11:23

1 Answer 1

15

Lets explore all the ways to form Date pickers

a)Using inputfield is best solution .

Disadvantage:Field level security and profile settings .If your object dont have edit access or field is hidden for any profile the same will apply and there is no way to bypass this security if you wish to by pass for various profiles (Note this is also advantage if your requirement is not to allow edit based on profile)

b)Hackish solution with input text

Visualforce page:

<apex:page controller="datePicker" id="mypage">
<apex:form>    
    Date: <apex:inputText value="{!datename}" size="10" id="demo"    onfocus="DatePicker.pickDate(false, this , false);" />    
</apex:form>
</apex:page>

Apex Controller:

  public class DatePicker {
     public String datename {get; set;}
 }

Disadvantage :hacked the JavaScript of salesforce and not officially recommended .

c)New trend after winter 14

<apex:pageBlockSection >
 <apex:outputLabel ></apex:outputLabel>
 <apex:input label="datePicker" value="{! fDate }" type="auto"/>
 </apex:pageBlockSection>


public class winter14Ctrl {

 public Date fDate { get; set; }
}

Advantage :This is native to salesforce and safely recommended

Disadvantages: Not supported in Firefox and IE. Source: http://caniuse.com/#search=input%20type Your all the instances must be updated to winter 13

d)Using jquery component to do this .Jquery library or jquery UI will have this component

disadvantage:More developer skills needed and lot of testing with different browser

4
  • Don't you mean winter 14 ? Commented Oct 11, 2013 at 6:55
  • oh thanks for correction.Spot on @Sdry its winter 14 Commented Oct 11, 2013 at 8:22
  • New trend after winter 14 is grate except it dose not work on IE9 or older
    – Ruwantha
    Commented Mar 28, 2014 at 4:49
  • Is there a special setting to do for datepicker to appear on public site? doesn't show up there. some security setting probably. Thanks. Commented Nov 15, 2016 at 23:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .