AnsweredAssumed Answered

Custom form field (date field) validation-handler

Question asked by azivotic on Mar 1, 2012
Latest reply on Aug 24, 2015 by stacy
Hi,

I'm trying to create my custom validation handler for some custom fields on workflow form. A have two fields: project begin date and project end date. For those two field i need two types of validation:
    1. project begin date can not be less then today's date
    2. project end date must be equal or grater then project begin date
However i'm still on beginning of creation custom validation-handlers. For start i just tried some simple validation handler for text field with numbers only but this isn't functioning. I did the following:

In my share-config-custom.xml i add
<config>
      <forms>
        <dependencies>
         <js src="/custom-form-validation.js" />
        </dependencies>
      </forms>
   </config>
and connect to my field
<field id="mcwm:shortProjectNumber" set="general" mandatory="true">
                  <constraint-handlers>
                     <constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.checkNumber" event="keyup" />
                  </constraint-handlers>
               </field>

custom-form-validation.js file is
Alfresco.forms.validation.checkNumber = function checkNumber(field, args, event, form, silent, message) {

  var ok = (field.value=="") || field.value.match("^\\d{4}\\/\\d{4}$");

  var valid = ok != null && ok;
 
  if (!valid) {
     YAHOO.util.Dom.setStyle(field.id, "border", "2px solid red");    
  }
  else {
     YAHOO.util.Dom.setStyle(field.id, "border", "");
  }
 
  // Inform the user if invalid
  if (!valid && !silent && form)
  {
     var msg = "The number must match the pattern 1234/5678.";
     form.addError(form.getFieldLabel(field.id) + " " + msg, field);
  } 
 
  return valid;
};

I put custom-form-validation.js file in my opt\tomcat\shared\classes\alfresco\web-extension folder, but there is no field validation at all? Any suggestion on this?

Regards,
Aleksadnar

Outcomes