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
mritzmritz 

how to use List<Date> for Input?

I want to fetch Start & End Date of each task on VF page and then perform operation on it (Save,update,delete)

But i am unable to pull data on VF page inputt fields

Apex:
public class TextClass1{
	public String err{get;set;}
	public List<Task__c> taskList{get;set;}
	public List<Integer> index{get;set;}
	public List<date> sDate{get;set;}
	public List<Date> eDate{get;set;}
	
	public TestClass1{
		sDate = new List<Date>();
		eDate = new List<Date>();
		index = new List<Integer>();
		err='';
		
		try{
			taskList = [SELECT id, name,start_date__c, end_date__c FROM Task__c];
			Integer i=0;
			for(Task__c t:taskList){
				sDate.add(t.Start_Date__c);
				eDate.add(t.end_date__c);
				index.add(i++);
			}
		}catch(Exception e){
			err=String.valueOf(e);
		}
	}
	public void saveAll(){
		update taskList;
	}
}

VF:
<apex:page id="page" showHeader="false" sidebar="false" doctype="html-5.0">
	
	<div>
		<center>{!err}</center>
		<apex:form id="form">
			<apex:repeat value="{!index}" var="i">
				Task Name: <apex:inputText value="{!taskList[i].name}"/>
				Start Date: <apex:input type="date" value="{!sDate[i]}"/>
				End Date: <apex:input type="date" value="{!eDate[i]}"/><br/>
			</apex:repeat>
			<apex:commandButton value="Save All"/>
		</apex:form>
	</div>

</apex:page>

I am getting this error:" Expected input type 'text', got 'date' for Id data type"

I have also tried this variation of VF code, but i dont like the extra link that appears besides the date input field
<div>
            <center>{!err}</center>
            <apex:form id="form">
                <apex:repeat value="{!taskList}" var="t">
                    Task Name: <apex:inputText value="{!t.name}"/>
                    Start Date: <apex:inputField type="date" value="{!t.Start_Date__c}"/>
                    End Date: <apex:inputField type="date" value="{!t.End_Date__c}"/><br/><br/>
                </apex:repeat>
                <apex:commandButton value="Save All"/>
            </apex:form>
        </div>

Any help would be appreciated.
mritzmritz
Correction in Vf code at line 11: <apex:commandButton action="{!saveAll}" value="Save All"/>
Deepak GulianDeepak Gulian
<apex:page id="page" controller="TextClass1" showHeader="false" sidebar="false" doctype="html-5.0">     
<div>
            <center>{!err}</center>
            <apex:form id="form">
                <apex:repeat value="{!taskList}" var="t">
                    Task Name: <apex:inputText value="{!t.name}"/>
                    Start Date: <apex:inputField type="date" value="{!t.Start_Date__c}"/>
                    End Date: <apex:inputField type="date" value="{!t.End_Date__c}"/><br/><br/>
                </apex:repeat>
                <apex:commandButton action="{!saveall}" value="Save All"/>
            </apex:form>
        </div>
</apex:page>
public class TextClass1{
	public String err{get;set;}
	public List<Task__c> taskList{get;set;}
	public List<Integer> index{get;set;}
	public List<date> sDate{get;set;}
	public List<Date> eDate{get;set;}
	
	public TextClass1(){
		sDate = new List<Date>();
		eDate = new List<Date>();
		index = new List<Integer>();
		err='';
		
		try{
			taskList = [SELECT id, name,start_date__c, end_date__c FROM Task__c];			
		}catch(Exception e){
			err=String.valueOf(e);
		}
	}
	public void saveAll(){
		update taskList;
	}
}
Do this simply.

 
mritzmritz
@Deepak, using this approach i get an additional date link which shows today's date adjacent to start date & end Date input fields. Is there any way to get rid of it?
Deepak GulianDeepak Gulian
<apex:page id="page" controller="TextClass1" showHeader="false" sidebar="false" doctype="html-5.0">     
<style>
    .dateFormat{
         visibility:hidden;
    }
<div>
            <center>{!err}</center>
            <apex:form id="form">
                <apex:repeat value="{!taskList}" var="t">
                    Task Name: <apex:inputText value="{!t.name}"/>
                    Start Date: <apex:inputField type="date" value="{!t.Start_Date__c}"/>
                    End Date: <apex:inputField type="date" value="{!t.End_Date__c}"/><br/><br/>
                </apex:repeat>
                <apex:commandButton action="{!saveall}" value="Save All"/>
            </apex:form>
        </div>
</apex:page>
Update with this.