AnsweredAssumed Answered

Form fields validation

Question asked by darkredd on Jun 1, 2015
Latest reply on Jun 11, 2015 by tonyrivet
Hello all,

I am trying to implement a custom form field validation, I have followed two tutorial along side studying the alfresco wiki and its related documentation; however I have not been able to achieve my objective.
1. http://blog.mwrobel.eu/field-validation-alfresco-share-form/
2. http://stackoverflow.com/questions/20710883/alfresco-share-forms-how-to-define-a-custom-validation-handler-for-a-non-mandat

Here is my js code which I am sure the function works:

if(typeof Mynamespace == "undefined" || !Mynamespace )
{
   var Mynamespace = {};
}

Mynamespace.forms.validation.checkEmailValidity = function checkEmailValidity(field, args, event, form, silent, message)
{
   var valid = true;

   valid = YAHOO.lang.trim(field.value).length !== 0;
   
   var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
   
   if(valid)
   {
      valid = re.test(field.value);
   }
   return valid;
}

I minified the script and place both the scripts in the "\webapps\share\components\form\" folder.
I have added the script to the form dependencies file "form.dependencies.inc".

And my form config:

<field id="my:field">
<constraint-handlers>
  <!– validation-handler param: js function name –>
  <constraint type="MANDATORY" validation-handler="Mynamespace.forms.validation.checkEmailValidity" event="keyup"/>
</constraint-handlers>
</field>


I am still unable to validate my field, what have I missed?

Help much appreciated.

Outcomes