Using xtype datefield not to select past date in CQ5
Please help me how to set minvalue as current date in xtype datefield.
Please help me how to set minvalue as current date in xtype datefield.
You need to write custom js and listeners to implement this.
(1) Create a js function to compare dates:\
/**
*Compares dates and return values in 0,-1,1,2
**/
MyUtility.compareDate = function(a_dateOne ,a_dateTwo)
{ var returnVal = 'default';
var l_dateOne;
var l_dateTwo;
l_dateOne = a_dateOne.split('/');
l_dateTwo = a_dateTwo.split('/');
if(l_dateOne[2] == l_dateTwo[2] && l_dateOne[1] == l_dateTwo[1] && l_dateOne[0] == l_dateTwo[0]){
returnVal = 0;
}
else if(l_dateOne[2] > l_dateTwo[2]){
returnVal = 1 ;
}else if(l_dateOne[2] == l_dateTwo[2]){
if(l_dateOne[1] > l_dateTwo[1]){
returnVal = 1;
}else if(l_dateOne[1] == l_dateTwo[1]){
if(l_dateOne[0] > l_dateTwo[0]){
returnVal = 1;
}else{
returnVal = -1;
}
}else{
returnVal = -1;
}
}else{
returnVal = -1;
}
return returnVal;
}
(2) Call this function using CQ listeners beforeSubmit event.
function(){
var currentDate = new Date();
currentDate=currentDate.format("d/m/y");
var eventDate=this.findByType('datefield')[0].getDateValue();
var event_year = new Date(eventDate).getFullYear();
var current_year = new Date(currentDate).getFullYear();
if(currentDate!=null)
{
eventDate=eventDate.format("d/m");
currentDate=currentDate.format("d/m");
eventDate = eventDate.concat("/"+event_year);
currentDate = currentDate.concat("/"+current_year);
var l_expirationDateCheck=MyUtility.compareDate(eventDate,currentDate);
if(l_expirationDateCheck==1)
{
var msg = CQ.I18n.getMessage("Selected Date cannot be less than current date");
CQ.Ext.Msg.show({
"title": CQ.I18n.getMessage("Error Message"),
"msg": msg,
"buttons": CQ.Ext.Msg.OK
});
return false;
}
}
}
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.