cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco share Form Validation

alfsender
Champ in-the-making
Champ in-the-making
Hello All,

I am trying to do validation in Alfresco share forms. I have one field say
"cm:name"
which is mandatory. I want to put validation in such a way that when user enters value in this field it should get copied to other field say
"my:productName"
. In case user wants he can modify value of
"my:productName"
.

For that i have created a custom function in forms-runtime.js file "Alfresco.forms.validation.copyProdNameValue". i have added this function to share-config-custom.xml for field
"cm:name"
like below.


<field id="cm:name" label="Name">
  <constraint-handlers>
     <constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.copyProdNameValue" event="keyup"/>
  </constraint-handlers>
</field>


This works when i enter value in
"cm:name"
say "Welcome Product" it copies value("Welcome Product") to
"my:productName"
. But when user modify value of
"my:productName"
(i.e. "Welcome Product") it again calls validation function for
"cm:name"
(i.e. "Alfresco.forms.validation.copyProdNameValue") so it copies value from
"cm:name"
to
"my:productName"
.

I am not sure whether this is default behavior that is serial validation.

Please send your valuable suggestion as putting validation in form is basic requirement.

Thank you.
1 REPLY 1

iblanco
Confirmed Champ
Confirmed Champ
Validators validate that a field is valid, so they are fired whenever the field changes or whenever the form must be validated to decide if submit button should be enabled or not. What you are doing is conceptually wrong.

I suggest you abandon this approach and instead consider <a href="http://wiki.alfresco.com/wiki/Forms_Developer_Guide#Controls">building a custom control</a> that "onchange", or on "keyup" or whatever suits better your needs, copies the value to the other control. You might <a href="http://wiki.alfresco.com/wiki/Forms#Configuring_Controls">check existing controls</a> as a reference.