user1480705
user1480705

Reputation: 89

how can i set todays date as default date for a date field in page properties in cq5

i have a date field(creation date) in page properties, which i want to default to todays date.

How i can accomplish this, i am using a listener on render event

even though i can read the value back, i cannot see to see the date set in page properties.

seems to me i am missing something basic

function(dateField) {

console.log("in render");
var todaysDate=new Date().format('m/d/Y');
console.log(todaysDate);
dateField.setValue(todaysDate);
CQ.Ext.getCmp("dateCreated").setValue(todaysDate);
console.log( CQ.Ext.getCmp("dateCreated").getValue());

}

Upvotes: 3

Views: 5568

Answers (1)

rakhi4110
rakhi4110

Reputation: 9281

You can create a widget with xtype "datetime" and apply the value as "now", in order to initialize the date field with today's date in case the author hasn't selected any.

An example widget is shown below :

"date":{"fieldLabel":"datetime","xtype":"datetime","name":"./date","value":"now","jcr:primaryType":"cq:Widget"}

This would work for Pageproperties as well.

Datetime widgets API.

Upvotes: 3

Related Questions