cancel
Showing results for 
Search instead for 
Did you mean: 

constraint-handlers dont work

ltardioli
Champ in-the-making
Champ in-the-making
Hello ppl,

I trying to do a validation using a constraint-handler in my share-config-custom.xml file. I have a model and a form that is working fine, but the validation just doesnt works;

The snippets of my code:

<property name="axcl:clienteContato">
               <title>Nome contato</title>
               <type>d:text</type>
</property>


<field id="axcl:clienteContato" label-id="prop.axcl_clienteContato">
                  <constraint-handlers>
                     <constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.mandatory" event="keyup" />
                  </constraint-handlers>
</field>

I turn on the debbug mode and seems that the constraint dont exist.
I've looked for something in logs files but there isnt a thing about that.

Anyone knows what I missing?

Thanks!

Ah, I'm using Alfresco CE 4.0e
6 REPLIES 6

afaust
Legendary Innovator
Legendary Innovator
Hello,

why are you trying to do a mandatory validation with an explicit validation handler? Why not simply make the property mandatory or set the mandatory attribute on the field configuration?
In order for a constraint validation handler to be invoked, the relevant constraint actually has to be present on a property / field definition. Unless you mark the property or the field definition as mandatory, the "MANDATORY" constraint won't be present and your mapping won't be evaluated.

Regards
Axel

ltardioli
Champ in-the-making
Champ in-the-making
Hello AFaust,
this is just a simple exemple to test the handlers. Actually I want to do another kind of validations on my fields.
For exemple, do a post to a webscript to get some values and fill the fields with it.

If I do sometihng like:

<dependencies>
            <js src="/share/res/js/formCustomFunctions.js" />
</dependencies>

<field id="axcl:clienteContato" label-id="prop.axcl_clienteContato">
                  <constraint-handlers>
                     <constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.myCustomFuncion" event="keyup" />
                  </constraint-handlers>
</field>

and put my formCustomFunctions.js in webapps/share/js and in my model definition set the property as a mandatory attribute, it is supposed to work?

Thanks!

afaust
Legendary Innovator
Legendary Innovator
Hello,

no. First of all, constraint-handlers is to be defined globally, not on a per-field basis, and second of all, you should not override MANDATORY, since all mandatory fields will then be validated with your custom handler.

Regards
Axel

ltardioli
Champ in-the-making
Champ in-the-making
Are you saying that is impossible define constraint-handlers per-fields or it is possible but is not a good pratice?

anand6105
Champ in-the-making
Champ in-the-making
Hi,
We are also facing the same problem while creating custom constraint handlers for a particular field. Now if we need to define the constraints globally, in which file we should define that. Please reply soon.

Thanks
Anand

aitbenmouh
Champ in-the-making
Champ in-the-making
I think there are something in the wiki that explain how to add you own constraint and then call it with event-handler check this http://wiki.alfresco.com/wiki/Content_Model_Constraints in the section Writing Further Constraints