cogWiki macros implementation of the LiveValidation javascript framework (http://livevalidation.com/documentation) to be used with validation specified in XWiki classes.
TypeXAR
Category
Developed by

Denis Gervalle, Flavius Olaru

Active Installs3
Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

Wiki macros implementation of the LiveValidation javascript framework to be used with validation specified in XWiki classes.

Macros

{{livevalidation /}}Provides client-side live validation of a single XObject based on the validation expressions and messages defined in its XClass.
{{livevalidationConfirmation /}}Validates that another field of the form match the value of an XObject property.
{{livevalidationCustom /}}Validates a XObject property value using a custom remote XWiki document that should returns "true" when valid or "false" when not valid, based on the field value and the property reference.
{{livevalidationEmail /}}Validates that XObject property value is a valid email address.
{{livevalidationFormat /}}Validates that XObject property value against a regular expression.
{{livevalidationPresence /}}Validates that XObject property value is present (ie. not null, undefined, or an empty string).

Usage

{{livevalidation form='inline' object='objectReference' /}}

{{livevalidationConfirmation form="formId" property="propertyReference" match="fieldId" failureMessage="A message to display when validation fail" /}}

{{livevalidationCustom form='formId' property='propertyReference' against='validationDocumentReference' failureMessage='Invalid value.'/}}

{{livevalidationEmail form='formId' property='propertyReference' failureMessage='Email format invalid.' /}}

{{livevalidationFormat form='formId' property='propertyReference' pattern='[A-Z]+' failureMessage='Only uppercase characters allowed.' /}}

{{livevalidationPresence form='formId' property='propertyReference' failureMessage='Non empty value required.' /}}

Either leave an empty space between macro calls to avoid inlining or put them all next to each other for inlining, both will work properly.

{{livevalidation /}}

{{livevalidation form='formId' object='objectReference' /}}
 Param  Description
 form  Unique ID of the form html element that will be validated before submission (Optional, default to inline).
 object  Object reference of the XObject to be validated.

{{livevalidationConfirmation /}}

{{livevalidationConfirmation form="formId" property="propertyReference" match="fieldId" failureMessage="A message to display when validation fail" /}}
 Param  Description
 form  Unique ID of the form html element that contains the validated field (Optional, default to inline).
 property  Property reference of the field to be validated.
 match  Identifier of the field that should match the property value.
 failureMessage  Message to be used upon validation failure.

Since version 1.2

{{livevalidationCustom /}}

{{livevalidationCustom form="formId" property="propertyReference" against="validationDocumentReference" args="an=additional&query=string" failureMessage="A message to display when false is returned" /}}
 Param  Description
 form  Unique ID of the form html element that contains the validated field (Optional, default to inline).
 property  Property reference of the field to be validated.
 against  Document reference of the document that will be AJAX requested to settle the validation.
 args  Additional QueryString passed over to the requested document with the property reference and the field value.
 failureMessage  Message to be used upon validation failure.

{{livevalidationEmail /}}

{{livevalidationEmail form="formId" property="propertyReference" failureMessage="A message to display when validation fail" /}}
 Param  Description
 form  Unique ID of the form html element that contains the validated field (Optional, default to inline).
 property  Property reference of the field to be validated.
 failureMessage  Message to be used upon validation failure.

{{livevalidationFormat /}}

{{livevalidationFormat form="formId" property="propertyReference" pattern="/regex/" failureMessage="A message to display when validation fail" /}}
 Param  Description
 form  Unique ID of the form html element that contains the validated field (Optional, default to inline).
 property  Property reference of the field to be validated.
 pattern  A regular expression pattern in Javascript syntax.
 failureMessage  Message to be used upon validation failure.

{{livevalidationPresence /}}

{{livevalidationPresence form='formId' property='propertyReference' failureMessage='Non empty value required.' /}}
 Param  Description
 form  Unique ID of the form html element that contains the validated field (Optional, default to inline).
 property  Property reference of the field to be validated.
 failureMessage  Message to be used upon validation failure.

Examples

Add the following lines to MyApp.MyAppSheet:

{{livevalidation object='MyApp.MyAppClass[0]' /}}

{{livevalidationConfirmation property='MyApp.MyAppClass[0].myprop' match='fieldId' failureMessage='This field should match myprop.' /}}

{{livevalidationCustom property='MyApp.MyAppClass[0].myprop' against='Code.IsUniqueValidator' failureMessage='myprop is required to be unique.' /}}

{{livevalidationEmail property='MyApp.MyAppClass[0].myprop' failureMessage='Email format is invalid.' /}}

{{livevalidationFormat property='MyApp.MyAppClass[0].myprop' pattern='/^[A-Z]*$/' failureMessage='myprop must contain only uppercase characters.' /}}

{{livevalidationPresence property='MyApp.MyAppClass[0].myprop' failureMessage='myprop cannot be empty.' /}}√

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Dependencies

Dependencies for this extension (org.xwiki.contrib.livevalidation:livevalidation-macros 1.2):

Tags:
    

Get Connected