How to get share form value from different fields?

Showing results for 
Search instead for 
Did you mean: 
Member II

How to get share form value from different fields?


In my share config custom form, I have defined a validation handler on the field by the javascript file custom-form-handler.js

            <js src="/js/custom-form-handler.js"/>

<field id="wfm:quantity1" label="Quantity1">
             <constraint type="MANDATORY" validation-handler="MyCustomNamespace.checkAmount" event="keyup"/>


if (typeof MyCustomNamespace == "undefined" || !MyCustomNamespace) {
    var MyCustomNamespace = {};

    function checkAmount(field, args, event, form, silent, message) {
    var valid = alert(field.value)

    return valid;

I can get the field (wfm:quantity1) by use "field.value" to retrive the form field value.

May I know how can I get the other form field value in my custom-form-handler.js?

As I know, the field parameter is referring to what field I defined in the share config custom form.

In my case, I want to get the other form field value to do calculation in the custom-form-handler.js,

something like calculation of the form field value of "wfm:quantity1" * "wfm:itemA"

May I know how can I achieve this?

In addition, how can I put the value into the other different form field?

something like: DOM.getElementbyId(fieldName).value= "wfm:quantity1" * "wfm:itemA"

Thanks for your kindly help, any feedbacks are appreciated.



3 Replies

Re: How to get share form value from different fields?

The validators in Share forms are always only "field" validators. They are not actually designed to validate values of multiple fields in conjunction. About the only thing you could do is try and lookup any other fields from the "form" parameter that is provided to you. This ultimately means you'd have to come up with some form of name convention to identify related fields or resort to hard-coding of field names in the JS code.

Member II

Re: How to get share form value from different fields?

Thanks Axel for the response.

Actually, I'm quite new on the share form customization....

From "form" parameter, it seems I could not find any other fields information, something I found was near to the result but just the event name "_fieldEvents:Object".

May I know how could I lookup the other fields from the "form" parameter? Let's assume I have a defined field in share-config-custom.xml called "wfm:itemA".

In addition, I would like to know more detail on how to identify related field by name convention or hard-coding of field names?

Is it meaning to change the field name from:

field = input#template_x002e_start-workflow_x002e_start-workflow_x0023_default-startWorkflowForm-alf-id1_prop_wfm_quantity1.number.invalid

to something like

Sorry for my poor understanding,
thanks for your kindly advise!

Re: How to get share form value from different fields?

The "form" parameter provided to the validator function is an instance of "Alfresco.forms.Form" (YUI module). This contains a "formId" property that you can use to retrieve the DOM element for the form. Via the DOM API you can iterate over all form input elements and check the name of the elements without having to resolve it by ID. Since you get the current field as the "field" parameter you can use its name to come up with a convention of which other fields should be relevant for a specific validation. E.g. you have a "xyz_aaaToSubtract" and a "xyz_aaaBase" field, you could add a generic validator to check that the "*ToSubtract" field is always less-or-equal the "*Base" field by focussing on the field suffix and extracting the common base name.