You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jens Maukisch <jm...@s-und-n.de> on 2004/07/12 09:39:52 UTC

CForms fd:javascript validation problem (validating two widgets against each other)

Hi,

I have two field widgets (datatype date) in my form
and I want to validate them against each other with
some javascript code.

The validation rule for the first widget is, that the
date must be after today and the js-code looks like this:
var error = true;
var value = widget.value;
var today = new Packages.java.util.Date();
if(today.after(value)) {
	widget.setValidationError(new
Packages.org.apache.cocoon.forms.validation.ValidationError	("errormsg",
true));	
	error = false;				
}				
return error;		

The date of the second widget must be after the date of the first widget.
The js-code looks like this (it might work with fd:assert as well, but it
should not matter atm);
var error = true;
var value = widget.value;
var parent = widget.getForm();
var widget1 = parent.lookupWidget("widget1");			
var value2 = widget1.getValue();
if(value.before(value2)) {
	widget.setValidationError(new
Packages.org.apache.cocoon.forms.validation.ValidationError("errormsg",
true));				
	error = false;
} 
return error;

The problem is that if the first widget is not valid and i want to validate
the second widget, the 
value of widget1 (widget1.getValue()) is always null.

The validation of the second widget works fine if the validation of the
first widget is ok.



Thanks for your help in advance,

kind regards
Jens


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms fd:javascript validation problem (validating two widgets against each other)

Posted by Joerg Heinicke <jo...@gmx.de>.
On 12.07.2004 09:39, Jens Maukisch wrote:

> I have two field widgets (datatype date) in my form
> and I want to validate them against each other with
> some javascript code.
> 
> The validation rule for the first widget is, that the
> date must be after today and the js-code looks like this:

...

> The date of the second widget must be after the date of the first widget.
> The js-code looks like this (it might work with fd:assert as well, but it
> should not matter atm);

...

> The problem is that if the first widget is not valid and i want to validate
> the second widget, the value of widget1 (widget1.getValue()) is always null.

Are you sure? The invalid value is always passed to the view again, so 
it can't be null.

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org