cancel
Showing results for 
Search instead for 
Did you mean: 

get value from parent node for custom field

pchoe
Champ in-the-making
Champ in-the-making
I am developing a custom form control for a form.  I want to be able to get a value from the parent folder for the form.

Is there a way to get the value of a property from the parent folder to be populated in the custom form, something like the following?

<div class="form-field">
      <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">*</span>></label>
      <input id="${fieldHtmlId}" type="text" name="${field.name}" value="${parent.properties['parentField'].value}"
              <#if field.disabled>disabled="true"</#if> />
   </#if>
</div>
2 REPLIES 2

parzgnat
Star Contributor
Star Contributor
There's no easy way to do this through configuration.  One approach would be to write a custom AJAX method that makes an asynchronous call to an Alfresco webscript when your form loads.  You can write this webscript in a way that retrieves the necessary information from the parent node and then on successful callback populates your form field(s) with the the metadata that you're looking for.  This is probably more work than you were hoping to have to do.

lotharmärkle
Champ in-the-making
Champ in-the-making
The main thing to talk about here is the missing controller hook: The current functionality of adding a custom form control to share is limited to configure a freemarker template which has to render the control HTML. This works for simple cases, but often some controller logic is required to drive the new control (execute a search for a list, query the parent, do a remote call to the master database). So why cant a webscript be configured? The webscript controller could then do all the fun stuff.

I only know a hacky and rather advanced way to do this know, by defining a surf region/component that is included in the control freemarker. The region/component is then wired to a share webscript.
This works but has the drawback that any parameters or state (e.g. the current node, form value) has to pushed using request attributes - because there is no way in surf/share to parameterise a region/component call in the freemarker.

Other solutions to your problem besides the AJAX way (I used all discussed here) whould be to add a form filter on the repository side that adds the required information from your parent space as "virtual fields" to the form model.

I hope Alfresco engineering will extend the custom form templates to include a webscript.

lothar