1

I'm hoping I can get some help on working with jquery easy autocomplete. It works fine but I can't enable the Key Event (I would like that we will be redirect to the correct link when pressing Enter key). I wanna use onChooseEvent but I'm not sure how to use it correctly.

My code:

<script>
  // http://easyautocomplete.com/guide#sec-template-links
  $(function() {
    var options = {
      data: [
          {"text": "Amazon", "website-link": "https://www.babelway.com/technology/amazon-mws/"},
          {"text": "AS2", "website-link": "https://www.babelway.com/technology/as2/"},
          {"text": "CSV", "website-link": "https://www.babelway.com/product-tour/csv-erp/"},
          {"text": "Dropbox", "website-link": "https://www.babelway.com/technology/b2b-integration-dropbox/"},
          {"text": "Edifact", "website-link": "https://www.babelway.com/technology/edifact/"},
          {"text": "Email", "website-link": "https://www.babelway.com/technology/b2b-integration-email/"},
          {"text": "Excel", "website-link": "https://www.babelway.com/technology/excel-erp/"},
          {"text": "Flat File", "website-link": "https://www.babelway.com/technology/flat-file/"},
          {"text": "FTP", "website-link": "https://www.babelway.com/technology/b2b-integration-ftp/"},
          {"text": "HTTP", "website-link": "https://www.babelway.com/technology/b2b-integration-http/"},
          {"text": "Idoc", "website-link": "https://www.babelway.com/technology/sap-idoc/"},
          {"text": "Json", "website-link": "https://www.babelway.com/technology/b2b-integration-json/"},
          {"text": "OFTP", "website-link": "https://www.babelway.com/technology/oftp/"},
          {"text": "Peppol", "website-link": "https://www.babelway.com/technology/peppol/"},
          {"text": "Rosettanet", "website-link": "https://www.babelway.com/technology/rosettanet/"},
          {"text": "SAP", "website-link": "https://www.babelway.com/technology/sap-edi/"},
          {"text": "SFTP", "website-link": "https://www.babelway.com/technology/b2b-integration-sftp/"},
          {"text": "Tradacoms", "website-link": "https://www.babelway.com/technology/Tradacoms/"},
          {"text": "UBL", "website-link": "https://www.babelway.com/technology/ubl/"},
          {"text": "VAN", "website-link": "https://www.babelway.com/technology/van/"},
          {"text": "X12", "website-link": "https://www.babelway.com/technology/x12/"},
          {"text": "X400", "website-link": "https://www.babelway.com/technology/x400/"},
          {"text": "XML", "website-link": "https://www.babelway.com/technology/xml-edi/"}
      ],


      getValue: "text",

      template: {
          type: "links",
          fields: {
              link: "website-link"
          }
      },

      list: {
          showAnimation: {
            type: "fade", //normal|slide|fade
            time: 400,
            callback: function() {}
          },

          hideAnimation: {
            type: "slide", //normal|slide|fade
            time: 400,
            callback: function() {}
          },

          match: {
            enabled: true
          },

          onChooseEvent: function() {

          }
      }
    };


    $("#template-links").easyAutocomplete(options);

  });
</script>

Thank you for your help :)

Alice J
  • 11
  • 3

2 Answers2

3

Do add these two lines inside your onChooseEvent method. Eg:

onChooseEvent: function() {
   let selected = $("#template-links").getSelectedItemData();
   location.replace(selected["website-link"]);
}
  • On choose and press of ENTER key, getSelectedItemData() method will return the data object of the selected text somewhat like this {text: "Amazon", website-link: "https://www.babelway.com/technology/amazon-mws/"} for Amazon.

  • selected["website-link"] will return the value of website-link (https://www.babelway.com/technology/amazon-mws/ for the above case) by invoking location.replace() method upon the link, you will able to redirect.

Hope, this will help. Thanks.

GSangram
  • 123
  • 10
-1

Try with

https://jqueryui.com/autocomplete/

This is much simpler to use.

Tammy
  • 1,122
  • 5
  • 19
  • 50