On 02/06/2015 11:04 PM, Jason Clemons wrote:
> 
> Hey Clemens, 
>  
> Thanks so much for the response I really appreciate it.  
>  
> Ok.. I have the first part working which I think is the "plumbing" but I'm 
> not sure of the next step. 
>  
> So far I've implemented this in my "sheet" page:
>  
> $doc.setValidationScript("ValidationSample.ValidationGroovy")
> $doc.validate()
>  

I think the option you have choose is only useful if you programatically call 
"doc.save()" - in that case you are also expected to do the validation and 
stuff by yourself.

However that is not your use case; you want to have a validation callback that 
gets called implicitly from the normal document save action.

To do that you should add the hidden input fields:

   <input type="hidden" name="xvalidate" value="1" />
   <input type="hidden" name="xvalidation" 
value="ValidationSample.ValidationGroovy" />

in the edit view of the sheet.
Probably this means that you have to wrap these two entries around an

#if ($xcontext.action=="edit")
   ...
#end

or the like to avoid having them in the normal view.
In that case the save action should figure out from the submitted form values:
  a) that it should do a custom validation of form submit (as xvalidate=1)
  b) and being told where to look for the validation script (by loading 
xvalidation=ValidationSample.ValidationGroovy)
In this case you should not need to add velocity code by your own to trigger 
the validation.

However you might need custom code to display the validation errors, as show in 
the next section of the tutorial,
or your users will never know what the problem is with their inputs ...


hope this helps,

Clemens

> I've validated that the page is returning a value from 
> ValidationSample.ValidationGroovy because when I explicitly change the values 
> in the ValidationSample.ValidationGroovy page, I see the value reflected on 
> my sheet when it is instantiated. 
>  
> I definitely understand that the "meat" of my validation logic goes in the 
> ValidationSample.ValidationGroovy page, and I understand how to return a 
> value from that page.. but how do I stop/intercept the actual save of the 
> page?
>  
> Currently regardless of the value I return (e.g.. true of false) the page 
> save happens the same. I think the part I'm missing is in the "How to 
> validate and save the document in CreateDoc" section of the tutorial listed 
> here ==> 
> http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with+validation+and+tooltips#HHowtovalidateandsavethedocumentinCreateDoc
>  although, I'm having some trouble understanding WHERE that code should live 
> and what exactly its function is. 
>  
> Does the CreateDoc implementation live in my application sheet, or does it 
> live in it's own sheet named CreateDoc? (which is how it is implemented in 
> the example).  Is the CreateDoc essentially the code that is "shimed" in 
> between the save event and the actual save? If so, how is it called?
>  
> Thanks again for all your help
> 
> 
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to