1

I'm trying to develop an 'autocomplete' feature on element which will get data from the remote database (using simple HTTP GET requests which will return JSON).

In the workflow form, in share-conifg-custom.xml i provided control template:

<control template="/com/test/mytest.ftl"/>

And this is mytest.ftl:


    <input type="text" name="search" id="search" placeholder="Type Something" list="searchresults" autocomplete="off">
    <datalist id="searchresults"></datalist>

    <script type="text/javascript">
        myHttp = new XMLHttpRequest();
        url='https://jsonplaceholder.typicode.com/posts';
        myHttp.open("GET", url);
        myHttp.send();
        myHttp.onreadystatechange = (e) => {
            var arr = JSON.parse(myHttp.responseText);

            for (var i =0; i < arr.length; i++) {
                var option = document.createElement("OPTION");
                option.setAttribute("value", arr[i]["title"]);
                document.getElementById("searchresults").appendChild(option);
            }
        }
    </script>

The problem is that it does not send any requests. What am I missing here?

As far as I understand, Freemarker template should convert it to HTML code and <script> tag should be executed on my browser.

Mike
  • 373
  • 4
  • 10
  • 1
    See https://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load/807895#807895 – Ori Marko Jul 24 '19 at 02:43
  • wow.. it is working! I though it is a problem with Alfresco, not with JS (especially because it was working on my PC) – Mike Jul 24 '19 at 11:16

0 Answers0