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]

Reply via email to