1
votes

I have been trying to validate my alfresco share workflow form for several days without success. This is what i have done.

  1. Configured my workflow in the share-config-custom.xml located in %TOMCAT_HOME%tomcat\shared\classes\alfresco\web-extension

  2. set my contraint handler as follows.

                    <constraint-handlers>
                        <constraint type="MANDATORY"
                            validation-handler="Alfresco.forms.validation.examplestaffnumber"
                            event="keyup" />
                    </constraint-handlers>
                </field>
    

    This field i have set to mandatory
    < label-id="Staff Number" id="leave:staffnumber" mandatory="true">

  3. I have created the contraint hanlder javascript and placed it at %ALFRESCO_HOME%\tomcat\webapps\share\js folder. This is both js and min.js

  4. Finaly added the js in form.get.head.ftl located at %ALFRESCO_HOME%tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\form folder like this <@script type="text/javascript" src="${page.url.context}/res/js/examplevalidation.js">

When I select my worflow form and key values in the staff number form nothing happens. I have checked in the firebug but there is no any call to the js. Where could i have gone wrong?

1

1 Answers

1
votes

I think you have not added dependencies for your java script. To do that add below code in your share-config-custom.xml located in %ALFRESCO_HOME%tomcat\shared\classes\alfresco\web-extension

<config>
    <forms>
        <dependencies>
            <js src="/js/examplevalidation.js" />
        </dependencies>
    </forms>
</config>

And your constrains handler should be like

<field id="leave:staffnumber" label-id="Staff Number" mandatory="true">
    <control template="/org/alfresco/components/form/controls/textfield.ftl" />
        <constraint-handlers>
            <constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.examplestaffnumber" event="blur"/>
        </constraint-handlers>
</field>

And function in your js should be like this:

Alfresco.forms.validation.examplestaffnumber = function examplestaffnumber(
            field, args, event, form, silent, message) {
    // your code with return statement
}

Hope this helps!!!