cancel
Showing results for 
Search instead for 
Did you mean: 

Custom form field (date field) validation-handler

azivotic
Champ in-the-making
Champ in-the-making
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
2 REPLIES 2

naman
Champ in-the-making
Champ in-the-making
Hi Aleksadnar,
Try putting your custom-form-validation.js in opt\tomcat\webapps\share folder.
Hope this hepls

stacy
Champ on-the-rise
Champ on-the-rise
Hi,

I have a requirement where i should provide a date validation as mentioned in the first post.

I am new to alfresco, i have a little understanding with docs and wiki, could any one here please elaborate as how i can achieve the custom validation.

Alfresco version: 5

Thanks in advance