AnsweredAssumed Answered

field validation is not working for non mandatory fields

Question asked by skadian1 on Jun 25, 2014
I am using alfresco 4.2.f and created my own custom work flow.

After that I tried to enabled field validation for non mandatory field but its not working.


I am sharing my share-config-custom.xml and custom-form-validation.js


1) share-config-custom.xml
=====================================================

<config evaluator="string-compare" condition="activiti$MyRequest">
            <dependencies>

         <js src="${page.url.context}/res/components/form/custom-form-validation.js" />

        </dependencies>
  <forms>

   <form>
    <field-visibility>
     <show id="wf:numberOfDays" force="true"/>
     <show id="wf:vacationMotivation" />
    </field-visibility>
    <appearance>
     <set id="" appearance="title" label-id="workflow.set.general" />
     <set id="info" appearance=""
      template="/org/alfresco/components/form/2-column-set.ftl" />
<set id="sop" appearance="" label="SOP"/>

     <field id="wf:numberOfDays"  label-id="workflow.field.message" >
   <!–  <field id="wf:numberOfDays"  label-id="workflow.field.message">
      <control template="/org/alfresco/components/form/controls/textfield.ftl">
       <control-param name="style">width: 95%</control-param>
      </control> –>
      <constraint-handlers>
         <constraint type="MANDATORY" validation-handler="sumitKadian" event="keyup" />
   </constraint-handlers>

     </field>

     <field id="wf:vacationMotivation" label-id="workflow.field.comment" set="sop">
<control template="/org/alfresco/components/form/controls/textfield.ftl" >
       <control-param name="style">width: 95%</control-param>
      </control>
   
     </field>
    </appearance>
   </form>
  </forms>
</config>


=============================================================

2) custom-form-validation.js

====================================================================


(function()
{
//Alfresco.forms.validation.checkNumber = function checkNumber(field, args, event, form, silent, message) {
sumitKadian = function checkNumber(field, args, event, form, silent, message) {

if (Alfresco.logger.isDebugEnabled()) {
         Alfresco.logger.debug("Validation handler, that should validate the date property with field id: '" + field.id + "'");
}

  var ok = (field.value=="") || field.value.match("55");



  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;

};
})();


==============================================================================


Thanks
Sumit Kadian

Outcomes