cancel
Showing results for 
Search instead for 
Did you mean: 

Form controls in popups

rjohnson
Star Contributor
Star Contributor
I have been trying to create popups to edit meta data that load and process from links on pages other than the document library.

To date I have done this for adding comments, but that form had no "form controls" on it. I am now trying to edit some metadata from a custom aspect. The form loads perfectly well provided that I do not add the date.ftl form control. As soon as I do that I get a javascript error "undefined is not a constructor". If I use textarea.ftl that does not throw an error on load nor does the auto complete control (from the forms32 sample project). That said, the autocomplete doesn't autocomplete (although no errors) and the textarea.ftl is silent.

All these controls work fine on the full "edit meta data" from off document detail view.

Is there a problem using form controls on popups that are launched off pages other than the document library or am I just doing something wrong?

I have included forms.js, object-finder.js and simple-dialog.js in the header of the page I am trying to launch the popup from.

Thank you

Bob Johnson
3 REPLIES 3

arnoldschrijve1
Champ on-the-rise
Champ on-the-rise
You could check if date-picker.js is included as well for correct function of Alfresco.DatePicker declared in date.ftl

rjohnson
Star Contributor
Star Contributor
Arnold

Thanks for the advice. Checking the javascript console was giving "null is not a constructor" which is its helpful way of advising me that I had indeed missed out the tags to include date.js and date-picker.js. I have now included these and the date control works.

Following your lead I went looking for an equivalent Javascript error for the autocomplete and I could not find one. Further delving around seems to indicate to me that the javascript in the autocomplete.ftl file is in some way stripped out when I load into a simple dialog popup but is included if I use a full page form.

Now, I'm the first to be sceptical here, but looking in the developer console in either Chrome or Safari, the code

<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>
absolutely exists in the page source when you use a static page and absolutely does not exist if you load the control into a pop up simple dialog (which, so far as I can see, programatically tags the contents of the template and hence the controls at the bottom of the page source to dynamically create the markup which is destroys when it gets hidden).

As this is at the end of the file, I tried moving it to the begining to no avail, and as I didn't believe myself, I replaced it with a simple

alert("Im here");

and that didn't fire, so I'm guessing that somehow the simple-dialog.js just doesn't load the CDATA. That said, I cannot see how or why from the source I have.

Has anyone managed to get the autocomplete working in a simple dialog popup that you are aware of?

Thanks again for the help thus far

Bob Johnson

arnoldschrijve1
Champ on-the-rise
Champ on-the-rise
Hi,

I didn't work with autocomplete, but also run into the issue of SimpleDialog not returning script code.
This is because the Alfresco.util.Ajax.request call in the SimpleDialog.show() method specifies 'execScripts = true'. Looking at Alfresco.util.Ajax class in alfresco.js it says about execScripts: Whether embedded <script> tags will be executed within the successful response. If it is set to true only sanitized javascript is returned, if false then javascript is included in the response (but the simpledialog is not working properly).
I solved this some other way, so unfortunately don't have a good solution for form controls with script in a simpledialog for you.