cancel
Showing results for 
Search instead for 
Did you mean: 

How to do business validation of a form before submitting the form?

satheeshkumar
Champ in-the-making
Champ in-the-making
Hi,

I have created a custom contentModel, as shown below,

      
<!– Each Produt Type folder should contain a prefix associated to it. –>
      <type name="hccm:productTypeFolder">
         <title>Product Type Folder</title>
         <parent>cm:folder</parent>
         <properties>
            <property name="hccm:prefix"> //Custom prefix fileld
               <type>d:text</type>
               <mandatory>true</mandatory>
               <!– TODO Need to add Regex Constraint for Prefix Field –>
            </property>
         </properties>
      </type>


I have created a form as shown below to create folders in the desired location
/slingshot/doclib2/doclist/file/site/" +site+ "/documentLibrary/Product%20Library
,

var site = "product-management";
//Read the node reference of Product Library under Document Library
var alfDestination = null;
//Derived based on the URI "/slingshot/doclib2/doclist/{type}/site/{site}/{container}/{path}"
var result = remote.call("/slingshot/doclib2/doclist/file/site/" + site
      + "/documentLibrary/Product%20Library");

if (result.status.code == status.STATUS_OK) {
   alfDestination = JSON.parse(result).metadata.parent.nodeRef;
};


var productName = {
      name:"alfresco/forms/controls/DojoValidationTextBox",
      config: {
         label:"Product Name",
         name:"prop_cm_name"
      }
};

var productTitle = {
      name:"alfresco/forms/controls/DojoValidationTextBox",
      config: {
         label:"Product Title",
         name:"prop_cm_title"
      }
};

var productDescription = {
      name:"alfresco/forms/controls/DojoValidationTextBox",
      config: {
         label:"Product Description",
         name:"prop_cm_description"
      }
};

var productPrefix = {
      name:"alfresco/forms/controls/DojoValidationTextBox",
      config: {
         label:"Product Prefix",
         name:"prop_hccm_prefix" //Custom prefix field
      }
};

var anpForm = {
      name : "alfresco/forms/Form",
      config:{
         okButtonLabel : "Create",
         okButtonPublishTopic : "ALF_CRUD_CREATE",
         okButtonPublishGlobal : true,
         okButtonPublishPayload : {
            //Specify the URL here to POST the data
            //Dereived based on the URI "/api/{item_kind}/{item_id}/formprocessor"
            url : "api/type/hccm%3AproductTypeFolder/formprocessor",
            //To create the folder under product Library of document library, we need the productLibrary nodeRer,So POST that too.
            alf_destination : alfDestination,
            alfResponseTopic :"PRODUCT_CREATE"
         },
         widgets:[]
      }
};

anpForm.config.widgets.push(productName,productTitle,productDescription,productPrefix);

model.jsonModel = {
      services:["alfresco/services/CrudService","example/widgets/ProductCreateListen"],
      widgets:[title,anpForm]
}


Now what I want is, if the user enter anything in "prop_hccm_prefix" field, I should make some ajax call and check the repository for any existence of the same prefix value under the location "
/slingshot/doclib2/doclist/file/site/" +site+ "/documentLibrary/Product%20Library
" and if exists, then show some red text in the UI like the prefix you entered is already used for some other "product type folder", is there a way I can achieve this.

I just want to achieve this similar to "REGEX" validation, I want to do AJAX validation.

Can you please help?

Thanks in Advance.
1 REPLY 1

satheeshkumar
Champ in-the-making
Champ in-the-making
I am able to achieve this,

Please refer the below link on how to do this, though it doesn't validate case-insensitively, but it may help someone.

https://forums.alfresco.com/forum/developer-discussions/alfresco-share-development/unable-do-case-in...