cancel
Showing results for 
Search instead for 
Did you mean: 

Autocomplete custom property from LIST

bazter
Champ in-the-making
Champ in-the-making
Hello,
I've made my own custom type with few custom properties and one of them is a LIST which picks values from MySQL database. Now, because the amount of values increased a lot, I decided to change it into text field with autocomplete feature which I want to keep at picking values from the same MySQL table. I'm kind of lost how I should do this. I discovered that there's some autocomplete.ftl template for this which uses some kind of data source but I have no idea how to make DataSource of my own using my MySQL database to pick values from.

I tried to start with something easier so I decided to try using the data source alredy included in alfresco (which i found somewhere on internet) but it doesn't seem to work neither. It should pick the users from alfresco.

my share-config-custom.xlm looks like this


   <field id="mb:autorF" set="obecne">
      <control template="/autocomplete.ftl">
         <control-param name="ds">/share/service/ds/autocomplete/alfrescoperson</control-param>
      </control>
   </field>



and the autocomplete.ftl looks like this

<#if field.control.params.ds?exists><#assign ds=field.control.params.ds><#else><#assign ds=''></#if>
<#if field.control.params.width?exists><#assign width=field.control.params.width><#else><#assign width='35em'></#if>

<style type="text/css">
#${fieldHtmlId}-AutoComplete {
    width:${width}; /* set width here or else widget will expand to fit its container */
    padding-bottom:2em;
}
</style>

<div class="form-field">
   <#if form.mode == "view">
      <div class="viewmode-field">
         <#if field.mandatory && !(field.value?is_number) && field.value == "">
            <span class="incomplete-warning"><img src="${url.context}/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
         </#if>
         <span class="viewmode-label">${field.label?html}:</span>
         <span class="viewmode-value">${field.value?html}</span>
      </div>
   <#else>
      <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
     <div id="${fieldHtmlId}-AutoComplete">
         <input id="${fieldHtmlId}" type="text" name="${field.name}"
          <#if field.control.params.styleClass?exists>class="${field.control.params.styleClass}"</#if>
          <#if field.value?is_number>value="${field.value?c}"<#else>value="${field.value}"</#if>
          <#if field.description?exists>title="${field.description}"</#if>
          <#if field.control.params.maxLength?exists>maxlength="${field.control.params.maxLength}"</#if>
          <#if field.control.params.size?exists>size="${field.control.params.size}"</#if>
          <#if field.disabled>disabled="true"</#if> />
         <div id="${fieldHtmlId}-Container"></div>      
     </div>
   </#if>
</div>

<script type="text/javascript">//<![CDATA[
(function()
{
      // Use an XHRDataSource
      var oDS = new YAHOO.util.XHRDataSource("${ds}");
      // Set the responseType
      oDS.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
      // Define the schema of the JSON results
      oDS.responseSchema = {
         resultsList : "result",
         fields : ["value"]
      };

      // Instantiate the AutoComplete
      var oAC = new YAHOO.widget.AutoComplete("${fieldHtmlId}", "${fieldHtmlId}-Container", oDS);
      // Throttle requests sent
      oAC.queryDelay = .5;
      // The webservice needs additional parameters
      oAC.generateRequest = function(sQuery) {
         <#if ds?contains("?")>
            return "&q=" + sQuery ;
         <#else>
            return "?q=" + sQuery ;
         </#if>
      };

      return {
         oDS: oDS,
         oAC: oAC
      };
})();
//]]></script>


unfortunately everytime i type in the field, nothing happens and catalina.out says

ERROR [alfresco.web.site] [http-apr-8080-exec-4] javax.servlet.ServletException: Could not resolve view with name 'ds/autocomplete/alfrescoperson' in servlet with name 'Spring Surf Dispatcher Servlet'


So i guess I'm doing something wrong or there's nothing like alfrescoperson DataSource there..

anyway I'd be really thankful, if you'd suggest me any way how to perform this kind of feature for my custom property, no matter how.. if there's a way how to do this with JavaScript or something, it would be really nice but I'm pretty sure I need to code some class file just like with the custom LIST picking it from database.

Regards,

Matouš
2 REPLIES 2

bazter
Champ in-the-making
Champ in-the-making
Should I post it into another section?

alhol
Champ in-the-making
Champ in-the-making
Check your
…/site-webscripts/org/alfresco/components/form/data
folder. It should contain autocomplete component (
autocomplete.get.config.xml, autocomplete.get.desc.xml
, etc.). And after that, try to use "google" instead of "alfrescoperson" in url
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.