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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to