cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Lundquist>
Subject Re: Passing Values into Forms-Definiton
Date Thu, 23 Jun 2005 17:40:02 GMT

On Jun 23, 2005, at 9:48 AM, Johannes Becker wrote:

> Hi,
> I've got a form-definition:
> ...
> <fd:validation>
>     <fd:range min="5" max="25"/>
> </fd:validation>
> ...
> My aim is to pass parameters into this definition-file. Why? Because 
> the max-attribute (of  fd:range)  varies (depending whats on some 
> database).
> Is there, for example, a way of mixing Forms-definiton and JXTemplate? 
> Could I then write something like this?
> ...
> <fd:validation>
>     <fd:range min="5" max="#{number/max}"/>
> </fd:validation>

Yeah, certainly.  You could do that.  In the flowscript, say something 

	var form = new Form ('cocoon:/myForm');

...then set up a pipeline to handle that request and generate the form 
definition from a JXT template.

However, this feels kind of baroque to me.  For dynamic validation 
requirements, my instinct is to do the validation manually in/through 
flowscript.  Unfortunately, this probably requires your flowscript 
validator function to be able to access local variables in the 
flowscript function that is setting up and invoking the form.  That's 
quite easy in the v2 forms flow API, but that AP is not recommended 
unless you're already using it, as it will be going away.  If you are 
using v2, you can do (if memory serves) something like:

	form.getWidget().foobar.onValidate =
		function (widget) {
			return isValid;		# (true or false)

I think in the standard API it might be trickier (again the issue is 
variable scope).  But maybe it wouldn't be tricky... something I never 
thought of until now, you could try adding the widget's validation 
function as a property of the widget:

	var something;

	form.getWidget().foo.validate =
		function() {
			return isValid;

then in the form definition:


If you try this, let us know whether it works! :-)  If it does, then it 
wouldn't be strictly necessary to add v2's "onValidate" feature to the 
standard form API (although it still might be a good idea...)


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message