Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

CompositeDateField and Validator

Go to End



Community Member, 66 Posts

7 May 2008 at 3:27am

Edited: 07/05/2008 3:29am

I need a control to put in someone's birthday.
It turned out, that all the other controls are not fitting to that scenario.
So i took CompositeDateField

But it turned out, that the RequiredFields validator doesn't work if i use this control.

I made a copy of the code (also needed for 'translation' of year and that things)

class EventCompositeDateField extends DateField

and tryed to make a better implementation of

function jsValidation()

dateParts = $(fieldName).getElementsByTagName('select');

doesn't work, because fieldnames are
fieldName + "[date]";
and nothing is found using the original javascript code.

So i made 'three checks, for any part of the field'

BUT: if i don't use

before doing a

no error is shown.
BUT if i use it, errors are shown 'immediately' and not if someone leaves the fields...

I think this is a problem, because validator only supports 'one field' things out of the box.
and here we have three of them...
but i'm not sure what element to put into the function

my code looks something like that:

     validateCompositeDateField: function(fieldName) {
		  var fln1 = fieldName + "[date]";
			var el1 = _CURRENT_FORM.elements[fln1];
			if(!el1 || !el1.value) return true;

		  var fln2 = fieldName + "[month]";
			var el2 = _CURRENT_FORM.elements[fln2];
			if(!el2 || !el2.value) return true;

		  var fln3 = fieldName + "[year]";
			var el3 = _CURRENT_FORM.elements[fln3];
			if(!el3 || !el3.value) return true;
		  //zyko: Without this line, there's no Error at all...
			if(el1.value == 'NotSet'){
 				validationError(el1,"Bitte gib einen gültigen Tag an.","validation");
				return false;
			if(el2.value == 'NotSet'){
 				validationError(el2,"Bitte gib ein gültiges Monat an.","validation");
				return false;
			if(el3.value == 'NotSet'){
 				validationError(el3,"Bitte gib ein gültiges Jahr an.","validation");
				return false;
			return true;			

any idea would be cool to hear ;-)