+ Start a Discussion
shra1_devshra1_dev 

date selector in vf page

Hi,

 

how to get date selector beside a field of type date in vf page.

 

 

for example:

fromDate

 

it could be possible with <apex:inputfield/>(it will come automatically) but i am not using the same standard controller in the page.

 

here the fromdate field's object is different from the object mentioned in the standardcontroller.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

Hello

 

Its my mistake. I had to put the inputField value as

<apex:inputfield value="{!Opportunity.closeDate}"/>

In your case the input field should be as below because your method name is getfromDate(). Sorry for the mistake.

 

<apex:inputfield value="{!fromDate.fromDate__c}"/>

All Answers

prageethprageeth

Hello it is no matter what your standard controller is.

For an example lets think your standard controller is Account and you need to display the 'closeDate' field which belongs to Opportunity sObject.

In your Controller method you have to return the Opportunity instead of returning the 'closeDate' field(See below).

 

 

public Opportunity getOpportunity() {
      Opportunity opp = [SELECT closeDate FROM Opportunity LIMIT 1];
      return opp;//returning the Opportunity object
}

 

 

Now in your VF page, access the closeDate fields as below.

 

<apex:page showHeader="false" standardController="Account" Extensions="MyClass">
    <apex:form>
        <apex:inputfield value="{!date.closeDate}"/> <!--Accessing closeDate field-->
    </apex:form>
</apex:page>

 

 

Now you will get the datePicker window.

 

shra1_devshra1_dev

Thanks for quick reply....I hav done wat u hav suggested...

 

But i am getting an error as

Unknown property 'UserProfile__cStandardController.date' 

 

i hav written the code as:

 

/* visual force*/

<apex:page standardController="UserProfile__c" extensions="LeaveAppClass">
       <apex:form >
                    fromdate : <apex:inputField value="{!date.fromDate}"/>
       </apex:form>
</apex:page>

 

/*controller*/

 

public LeaveApp__c getfromDate()
    {
        LeaveApp__c lcon = [select fromDate__c from LeaveApp__c LIMIT 1];
        return lcon;
    }

 

 where am i doing the mistake...please help me

 

prageethprageeth

Hello

 

Its my mistake. I had to put the inputField value as

<apex:inputfield value="{!Opportunity.closeDate}"/>

In your case the input field should be as below because your method name is getfromDate(). Sorry for the mistake.

 

<apex:inputfield value="{!fromDate.fromDate__c}"/>
This was selected as the best answer
shra1_devshra1_dev

thanks prageeth.......

 

it is working but on page load it should not diplay the value in it . can't we make that field to empty  on page load.

prageethprageeth

Hello 

shra1_devshra1_dev

Hi prageeth,

 

In the fromDate field it is showing the value of fromDate of the first record in the LeaveApp object.

 

It should not show that value . it should be empty by default. then the user should select the date from Datepicker.

 

It is required because i am placing another field toDate which could be empty.

 

If it is not empty at page load the user needs to delete the content in toDate field every time he visits the page(If he doesn't want to mention toDate)