cancel
Showing results for 
Search instead for 
Did you mean: 

How to access form fields value in a control component ?

stondini
Champ in-the-making
Champ in-the-making
Hello,

I have a form with many fields and a custom javascript object-finder for an association (this object is a subclass of Alfresco.ObjectFinder).

Here the share-config-custom.xml :.
<code>
<appearance>
   <field id=“xyz:textField" mandatory=“true" />
   <field id=“xyz:assocField" mandatory="true">
      <control template=“/xyz/components/form/controls/searchPicker.ftl">
         <control-param name="showTargetLink">true</control-param>
         <control-param name="name="linkedField""> xyz:textField </control-param>
      </control>
   </field>
</appearance>
<code>

The user fills the first field in and when it clicks on the button “select” of the association field,
a custom selection box appears and I’d like to use the value of the first field in it.

In fact, I’d like to have access to the entier form fields in my custom control.
I tried to use something like this :
<code>
var form = new Alfresco.forms.Form(this.objectFinder.formHtmlId);
form.init();
var fields = form.getDataFields();
<code>
But the current association value is not present (other fields are present).

Everything is on the client side, no server access because the form fields are not save when user fills them in.

Do you have some advices or examples ?

Thank you.
5 REPLIES 5

mitpatoliya
Star Collaborator
Star Collaborator
It would be more useful if you also suggest what you are trying to achieve. I mean why you are trying to reuse those form fields?

stondini
Champ in-the-making
Champ in-the-making
OK.
I need to use the values of the fields in the "modal" search box to set some filters.
For example, a form with two fields is shown.
A user select a country in the first field and clicks the "select" button of the second field.
A search box appears to select some documents filtered by the country.
It's a kind of contextual search. It depends on the values of the form fields.

aaditvmajmudar
Confirmed Champ
Confirmed Champ
You can get any form field of any form by "field generic id + id of field".

e.g If your field is defined in form like <show id="myModel:customProp">, then you can get this field in JS file with Dom.get(field generic id+"_prop_myModel_customProp").

Now "field generic id" you can set in form.lib.ftl file in hidden field, so that will be available on every form and you can use in any of your custom control.(in form.lib.ftl file, args.htmlid = field generic id).

So now you can get one field value to filter second field value.

Hope this helps.

Thanks,

stondini
Champ in-the-making
Champ in-the-making
Thank you for the response.
I already tested the way you mention.
The field id is something like "page_x002e_data-form_x002e_task-edit_x0023_default_assoc_myModel_customPropAssoc".
And the value of Dom.get(…) is null.

So, I tried to debug and I found the field id should be "page_x002e_data-form_x002e_task-edit_x0023_default_assoc_myModel_customPropAssoc-cntrl" (notice the "-cntrl" postfix).
With that id, the value is a html div element ant the inner html is like :

<div id="page_x002e_data-form_x002e_task-edit_x0023_default_assoc_myModel_customPropAssoc-cntrl" class="object-finder">
   <div id="page_x002e_data-form_x002e_task-edit_x0023_default_assoc_myModel_customPropAssoc-cntrl-currentValueDisplay" class="current-values object-finder-items">
      <div><img src="/share/res/components/images/filetypes/generic-file-16.png" width="16" alt="" title="PM-123"> <a href="/share/page/site/PM-123/document-details?nodeRef=workspace://SpacesStore/e5827519-5e22-4cac-8241-2c979474cbdd">PM-123</a>
      </div>
   </div>        
</div>


It's strange to use DOM to get a form field value instead of the Alfresco API no ?

I need the "real" initial field value given by the server call (the "data model" returned by the server in json).

Do know another way to do that ?
With the Alfresco client Javascript API for example ?

aaditvmajmudar
Confirmed Champ
Confirmed Champ
If you want to get default value provided by JSON response for any association then you can check loadSelectedItems method in object-finder js file of that association component.

For any other field except association, you can get the value like above mentioned.

Thanks,