Thanks very much for your help there. This is exactly what I was looking
for.
However, the snippets you have provided don't seem to work on my
installation.
this is what I have:
form.getWidget().addValidator(newValidator(function(widget) {
var loginWidget = widget.getWidget("login");
if( loginWidget.getValue() == "test" ) {
var validationError =
new Packages.org.apache.cocoon.forms.validation.ValidationError("login
taken.");
loginWidget.setValidationError( validationError );
return true;
}
return false;
}));
gets completely ignored when it comes to validation.
if I add the validator to the widget I want to validate directly, like
form.getWidget("login").addValidator(newValidator(function(widget) {
I get the following exception:
Original Exception: TypeError: Cannot convert null to an object.
(resource://org/apache/cocoon/forms/flow/javascript/Form.js; line 115)
at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:581)
at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:541)
at org.mozilla.javascript.NativeGlobal.typeError0(NativeGlobal.java:546)
at org.mozilla.javascript.ScriptRuntime.toObject(ScriptRuntime.java:497)
at org.mozilla.javascript.JavaAdapter.toObject(JavaAdapter.java:401)
at adapter0.validate(<adapter>)
at
org.apache.cocoon.forms.formmodel.AbstractWidget.validate(AbstractWidget.jav
a:215)
at org.apache.cocoon.forms.formmodel.Field.getValue(Field.java:113)
at org.apache.cocoon.forms.formmodel.Field.validate(Field.java:190)
at
org.apache.cocoon.forms.formmodel.WidgetList.validate(WidgetList.java:104)
at
org.apache.cocoon.forms.formmodel.AbstractContainerWidget.validate(AbstractC
ontainerWidget.java:93)
at org.apache.cocoon.forms.formmodel.Form.doValidate(Form.java:297)
at org.apache.cocoon.forms.formmodel.Form.process(Form.java:244)
can't figure it out.
jakob
----- Original Message -----
From: "Bruno Dumon" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 29, 2004 6:14 PM
Subject: Re: cocoon forms - flow custom validator
> On Thu, 2004-04-29 at 09:52, Jakob Schwendner wrote:
> > Hi there,
> >
> > I am using cocoon 2.1.5-dev (CVS 28/04/2004) to perform form handling
> > with the Cocoon Forms framework.
> > Everything works fine and the widgets get validated nicely, however,
> > when I try to add custom validation to the flowscript by setting the
> > form.validator it gets completely ignored.
> >
> > var form = new Form("forms/register.xml");
> > form.validator = function(form, bizdata) {
> > var validationError =
> > new
> > Packages.org.apache.cocoon.forms.validation.ValidationError("xxx");
> >
> > if (form.getWidget("login").getValue() == "test") {
> > form.getWidget("login").setValidationError(validationError);
> > return false;
> > }
> >
> > return true;
> > }
> >
> > form.showForm( get_page_name(), bizdata );
> >
> > I think the above code should be correct. I tried to do some debugging
> > and am sure that the validator function just doesn't get called by the
> > Forms class.
> > When I use the JavaScript debugger I can't actually get past the
> > loadPageAndWait(). This is because when I break at the continuation
> > the debugger jumps to the function declaration of the last called
> > function, does however not go into the function when I tell it to.
> >
> > Any ideas as to why this behaviour occurs?
>
> Does it work different then before? Note that the custom validator only
> gets called after the normal validation ended successfully (thus also
> all required fields must be completed)
>
> Since you're using latest CVS anyway, I'd suggest not to use that
> validator function but make use of the possiblity to add
> "WidgetValidators" to widgets. If you add such a WidgetValidator to the
> form itself, then this would be very similar to the form.validator
> function (except that it becomes part of the normal validation cycle,
> not something that is done afterwards).
>
> To do this from within flowscript:
>
> form.getWidget().addValidator(newValidator(function(widget) {
> (see javadoc of class WidgetValidator for more info
> on the behaviour of the code herin, basically if
> there's an error return false + set a validation
> error on some widget)
> });
>
> with newValidator being an utility function to implement a java
> interface from within flowscript:
>
> function newValidator(validatorFunction) {
> var validator = {validate: validatorFunction };
> var adapter = new
> JavaAdapter(Packages.org.apache.cocoon.forms.validation.WidgetValidator,
> validator);
> return adapter;
> }
>
> There might be some typos in all of the above.
>
> --
> Bruno Dumon http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> [EMAIL PROTECTED] [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]