I've a problem with an application developed with Cocoon 2.1.3.
I'm trying to do validation inside a JXForm using Flow.
I'm using sitemap matches like this:
<!-- Here is called jxform -->
<map:match pattern="admin-*-form">
<map:call function="jxform">
<map:parameter name="function" value="{1}"/>
<map:parameter name="id" value="form-{1}"/>
<map:parameter name="validatorNamespace"
value="http://www.ascc.net/xml/schematron"/>
<map:parameter name="validatorSchema"
value="content/static/admin/schematron.xml"/>
</map:call>
</map:match>
<!-- Here is "generated" jxform -->
<map:match pattern="admin-jxforms-*-xsp">
<map:generate src="content/static/admin/{1}.xsp" type="serverpages"/>
<map:transform type="jxforms" label="debug"/>
<map:transform type="xslt" src="stylesheets/jxforms-default.xsl"/>
<map:transform type="xslt" src="stylesheets/jxforms2html.xsl"/>
<map:serialize type="xml"/>
</map:match>
XSP page which creates jxform (excerpt): basically outputs JXForm with inputs
and selectS fetched from a DB source using ESQL.
...
<xf:form id="form-addresource" view="addresource"
xmlns:xf="http://apache.org/cocoon/jxforms/1.0">
...
<!-- BTW: what does it mean and it MUST exists "error" element? -->
<error>
<xf:violations class="error"/>
</error>
...
<!-- An input -->
<xf:input ref="/phone_number">
<xf:label>bla bla</xf:label>
<!-- it's REQUIRED violations in order to perform validation on this input? -->
<xf:violations class="error"/>
</xf:input>
...
And in my JS flow:
function addresource(form) {
...
// Show jxform
form.sendView("dmin-jxforms-addresource-xsp",
function(form) {
// I use Database.js (PetShop sample) in order to query a DB and exceptions
// to catch DB errors
try {
// Do SQL on datasource...
} catch(e) {
// Error coming from DBMS (ie. duplicate PK)
// Add violation in jxform
// User should see again this jxform with phone_number with Error!! string
// showed
form.addViolation("/phone_number", "Error!!");
}
});
...
}
Schematron for jxform is like this:
...
<phase id="addresource">
<p>bla</p>
<active pattern="checkphone"/>
</phase>
<pattern id="checkphone" name="adduser validation pattern">
<rule context="/phone_number">
<assert test="string-length(.) > 1">drin drin!!</assert>
</rule>
</pattern>
...
The result is that cocoon, when user fill this jxform and there's an error,
show again jxform but WITHOUT any string indicating ie. "drin drin!!"
or "Error!!" as indicated in JS and schematron (which is desidered behaviour).
I'm missing something? What are the exact steps in order to do jxform
validation using JS?
TIA,
--
Luca Nora