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
code redcode red 

Date field on VF page

Hi all;

 

I have a custom VF page with a date field, which uses the standard VF calendar widget. Every time I open the form in Edit mode the saved date is wiped out?

 

The field value is saved in a custom object, it is not a required field, and there are no triggers or validations affecting it. (I have this same problem in some other pages too, all with the same field attributes.)

 

Does anyone also have this problem, and are there solutions?

 

Thanks in advance.

AmitSahuAmitSahu

What is the tag you are using for fetch this ?

 

Apex:outputField / inputField?

code redcode red

Hi j020, 

Thank you for the reply. The field is:

<apex:inputField value="{!var.myField}"/> and enclosed within an action region. I note that if I don't change the value (i.e., enter a new date) in page edit mode, the original saved value is unchanged. That might be normal behavior, but with other editable fields in the edit page mode the previous saved value is shown. In my case, the calendar value in edit page mode is not displayed. Again, this may be normal behavoir for a date field, but it leads the user to believe the field is empty.

 

When I set the myField (date) attribute to 'required', in page edit mode the field (which did have a stored date), now requires a date be entered.

 

Any advice is appreciated.

 

Regards

hemantgarghemantgarg

I think it is not the standard behavior , on date input field, the existing date value should get populated , there may be some issue with the {!var.myField} , can you post the lines of code , so that i can check the issue ?

code redcode red

Hi hemantgarg,

 

Here is the VF page code for the date field on the Edit page:
<apex:pageBlock id="Page_Block" >
<apex:actionRegion >
<apex:pageBlockSection title="Basic Information" columns="1" collapsible="false">
<apex:inputField value="{!theAFCA.name}" required="true"/>
<apex:inputField value="{!theAFCA.Corrective_Action_Due_Date__c}"/>
<apex:pageBlockSectionItem >
</apex:actionRegion>
</apex:pageBlock>


Here is the code from the page Extension:
public with sharing class AFCAExtension {
private Audit_Finding_Corrective_Action__c theAFCA;
theAFCA = [select name,Corrective_Action_Due_Date__c
from Audit_Finding_Corrective_Action__c where id =: AFCAId];
public sObject getRecord(){
return theAFCA;
}
public void setTheAFCA(Audit_Finding_Corrective_Action__c val){
theAFCA=val;
}
public Audit_Finding_Corrective_Action__c gettheAFCA(){
return theAFCA;
}
}


Thank you for your help.

hemantgarghemantgarg

I tried this example in my dev org with contact object as below :-

 

public with sharing class CommunityExt {
private string conId='003U0000001z2Cw';

private Contact theAFCA = [select name,BirthDate from COntact where id=:conId];

public sObject getRecord(){
return theAFCA;
}

public void setTheAFCA(contact val){
theAFCA=val;
}

public contact gettheAFCA(){
return theAFCA;
}
}

 

/***********************************page***************************/

<apex:page controller="CommunityExt">
<apex:form>
<apex:pageBlock id="Page_Block" >

<apex:actionRegion >
<apex:pageBlockSection title="Basic Information" columns="1" collapsible="false">
<apex:inputField value="{!theAFCA.name}" required="true"/>
<apex:inputField value="{!theAFCA.birthDate}"/>
<apex:pageBlockSectionItem />

</apex:pageBlockSection>
</apex:actionRegion>
</apex:pageBlock>
</apex:form>
</apex:page>

 

I found it works good, the birthdate is getting populated on the page.It means your code is fine, Please check if "AFCAId" contains any value or not ?