You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Johannes Becker <jo...@gmx.net> on 2005/06/23 18:48:33 UTC

Passing Values into Forms-Definiton

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>
...

Thanks
Jonny


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


Re: Passing Values into Forms-Definiton

Posted by Mark Lundquist <ml...@wrinkledog.com>.
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 
like:

	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:

	<fd:validate>
		<fd:javascript>
			widget.validate();
		</fd:javascript>		
	</fd:validate>

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...)

HTH,
—ml—


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


Re: Passing Values into Forms-Definiton

Posted by Mark Leicester <ma...@efurbishment.com>.
Hi Jonny,

You can generate your form definition files using jxtemplate (in a 
cocoon pipeline). Then when you want to reference your definition file, 
use cocoon:// to access it.

HTH,
Mark

On 23 Jun 2005, at 17:48, 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>
> ...
>
> Thanks
> Jonny
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>


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