Hello Xwiki users,
I’m calling some server side validation from a template file, the validation seems to be working but it redirects to the preview of the page instead of back to edit when validation returns False
Do I somehow need to tell xvalidate to redirect to the correct editor? The code works fine when placed in an AWM sheet but doesn’t seem to like being called from a template file.
This is how I include the validation in the template:
#set($mydoc = $xwiki.getDocument("Content Manager.Code.Form and Validation"))
$mydoc.getRenderedContent()
Where “Content Manager.Code.Form and Validation” contains:
<div class="xform">
## Iterate over the properties of the Content Manager Reduced Class
#set($discard = $doc.use('Content Manager.Code.Content Manager Reduced Class'))
#set($class = $doc.getObject('Content Manager.Code.Content Manager Reduced Class').xWikiClass)
#foreach($prop in $class.properties)
<b>$prop.prettyName</b>
$doc.display($prop.getName())
#end
</div>
## Invoke validation
<input type="hidden" name="xvalidate" value="1" />
## Set the Groovy script which will be used for validation
<input type="hidden" name="xvalidation" value="Content Manager.Code.Content Manager GroovyValidation" />
#if(($xcontext.validationStatus.errors&&$xcontext.validationStatus.errors.size()>0)||($xcontext.validationStatus.exceptions&&$xcontext.validationStatus.exceptions.size()>0))
<div class="validation-errors" style="border: 1px solid grey; padding: 10px;">
This is a recap of all errors in this page (change the form to show errors only at the top or only next to the fields):
#foreach($error in $xcontext.validationStatus.errors)
<font color="red">$xwiki.parseMessage($error)</font><br />
#end
#foreach($exp in $xcontext.validationStatus.exceptions)
<font color="red">$exp</font><br />
#end
</div>
#end
Can anyone tell me what I’m doing wrong?
Thanks,
Ben