Hi,
You use the class editor to define your class, its properties and
validation regex for certain properties. That is just the first step.
Now you need to create a sheet [1] for your class in order to be able to
display documents having objects defined by your class.
Inside the sheet is where you do the display of your fields and where you
can also trigger the validation and display validation errors.
The link you gave about validation might contain some deprecated notions,
but generally the idea is the same. Here is a rough example of how to use
that input inside your sheet:
{{velocity}}
Errors: $context.validationStatus.errors
{{html}}<input type="hidden" name="xvalidate" value="1"
/>{{/html}}
Name: $doc.your_name
{{/velocity}}
The first line (after the velocity macro call) prints validation errors, if
any, the second line is the xvalidate invisible marker that marks the
inline editor's form as validating its inputs (based on the validation
regex of each field defined in the class) and the third line is just
displaying the "your_name" field from the object inside the current
document.
If you go in (inline) edit mode, the sheet will show an input for the
"your_name" field. You enter data and press save. If the data does not
validate, the page will not be saved but it will be reloaded and showing
the validation error.
To answer your question, yes, you do need to have the xvalidate input
inside your class sheet, otherwise the standard XWiki save button for the
inline edit mode will not know if to enable or not validation. If it is not
there, it will just save whatever you enter in the fields.
If you want javascript validation just follow the instructions [2] at the
bottom. The example you find there is not a clean one, since you should not
use inline javascript but a JavaScriptExtension [3] and instead of those
html form elements (input, label, etc) you can just do $doc.<fieldName> and
use "<className>_<objectNumber>_<fieldName>" (e.g.
"Main.Class_0_your_name") as id in the javascript code.
Hope this helps,
Eduard
----------
[1]
http://extensions.xwiki.org/xwiki/bin/view/Extension/Sheet+Module
[2]
http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with+vali…
[3]
http://platform.xwiki.org/xwiki/bin/view/DevGuide/SkinExtensionsTutorial#HM…
On Thu, Aug 7, 2014 at 10:35 AM, O.J. Sousa Rodrigues <
osoriojaques(a)gmail.com> wrote:
Hi there!
How to create validations using regular expressions? Is this (
http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with+vali…
) still up to date with xwiki601? I just added the expression to the class
(
http://i.imgur.com/u9sieKB.png ) in many different ways using sure thing
expressions too like one from the wiki (/^.{2,20}$/) and i don't get it to
work...
do i really have to add <input type="hidden" name="xvalidate"
value="1" />
and if yes where to add it? I am using the class editor to add and modify
the class properties and not html.
Thanks in advance!
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users