Date validation

Author Message

Alejandro Serrano

Wednesday 27 September 2006 8:36:28 am

This may be a very simple task or already been documented, but I can't find any doc about it.
I have a 'event' class with 'event_start' and 'event_end'. I need to validate that event_end is >= event_start.
Is there any way to do it?

Nate Parsons

Wednesday 27 September 2006 12:59:23 pm

I was unable to find any "eZPublish" way of doing this sort of validation, I ended up using javascript to validate the two form fields & modifying my form's action:

<b>The Form Action</b>

action={concat("/content/edit/",$object.id,"/",$edit_version,"/",$edit_language|not|choose(concat($edit_language,"/"),''))|ezurl}>

<b>Javascript Example Code</b>


if(endUnixtime <= startUnixtime){				
		expMenu('error_start_end_date','show');
		expMenu('error_display','show');
		return false;
	}
	else{
		if(endUnixtime > startUnixtime)
			expMenu('error_start_end_date','none');		
		//Make sure that the end date is later than today
		var endDate = new Date(yy,(mm-1),dd);
		var today = new Date();
		var year = today.getFullYear();
		var month = today.getMonth();
		var day = today.getDate();
		var today = new Date(year,month,day,00,00,00);
		var dateDiffDays = parseInt((endDate - today)/(1000*60*60*24));
		if(dateDiffDays <= 0 ){
			//alert('The end date must be later than today\'s date.');
			//alert('Error2: dateDiffDays: '+dateDiffDays);
			expMenu('error_end_today_date','show');
			expMenu('error_display','show');
			return false;
		}
		else{
			expMenu('error_end_today_date', 'none');
			return true;
		}
        }
}
function datetounixtime(yy,mm,dd,hh,min,sec){
	var humDate = new Date(Date.UTC(yy,(mm-1),dd,hh,min,sec));
	return (humDate.getTime()/1000.0);

---------------------------------------------------------------------------------
I look forward to an America which will not be afraid
of grace and beauty.

-------------JFK 10/26/63------------------------------------------------

Kristof Coomans

Tuesday 03 April 2007 6:27:48 am

There's now a hack in progress which allows to add several kinds of custom validation when storing an object: http://projects.ez.no/objectvalidation

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.