I am trying to add autocomplete input field below checkout shipping-method. But it is not working. When i look at chrome console i see those errors.

Error messages:

knockout.js:3012 Uncaught TypeError: Unable to process binding "afterRender: function (){return setSearchElement }" 
Message: Cannot read property 'element' of undefined
at $.(anonymous function).(anonymous function)._create (
at $.(anonymous function).(anonymous function)._create (
at $.(anonymous function).(anonymous function)._createWidget (
at new $.(anonymous function).(anonymous function) (
at HTMLInputElement.<anonymous> (
at Function.each (
at jQuery.fn.init.each (
at jQuery.fn.init.$.fn.(anonymous function) [as autocomplete] (
at UiClass.setSearchElement (
at init (

And when i click to input field or type

Uncaught TypeError: Cannot read property 'element' of undefined
at $.(anonymous function).(anonymous function)._close (
at $.(anonymous function).(anonymous function)._close (
at $.(anonymous function).(anonymous function).close (
at $.(anonymous function).(anonymous function).close (
at $.(anonymous function).(anonymous function).blur (
at HTMLInputElement.handlerProxy (
at HTMLInputElement.dispatch (
at HTMLInputElement.elemData.handle (

I have searched for an answer and found this, but it seems to be unrelated to current errors?

My files:


<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
    <item name="shippingAdditional" xsi:type="array">
        <item name="component" xsi:type="string">uiComponent</item>
        <item name="displayArea" xsi:type="string">shippingAdditional</item>
        <item name="children" xsi:type="array">
            <item name="additional_block" xsi:type="array">
                <item name="component" xsi:type="string">Vendor_checkoutShipping/js/view/checkout/shipping/additional-block</item>
                <item name="template" xsi:type="string">Vendor_checkoutShipping/checkout/shipping/additional-block</item>


define(['uiComponent'], function (Component) {
'use strict';
var availableTags = [
return Component.extend({
    setSearchElement: function (element) {
            source: availableTags,
            minLength: 2


    <div >ADDRESSES</div>
    <div class="addresses red ui-widget">
        <label for="tags">Tags: </label>
        <input  id="tags" class="inputAddresses" data-bind="afterRender: setSearchElement">

I have asked this before, but the answers i got did not solve those errors. I have messed with it quite some time trying different ways to solve it but nothing changes the output error. I have: cleared chrome cache, deleted pub/static directory and run setup:upgrade. Also no other module is installed to test environment. It makes no difference if i use id or element in jQuery('#tags').autocomplete(..) except that with elements Magento adds autocomplete="off" to input. What could cause these errors??


Magento 2 uses jQuery-ui version: "1.10.4" and Magento version 2.1.2.


I have found out that the element mentioned in those error messages is this:

<ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all" id="ui-id-29" tabindex="0" style="display: none;"></ul>

But i have still not closer to the solution (Why this error is happening? - I think that something is wrong with knockoutJs might it be view model some how ...?)? I have no idea what should i do next!

  • you need to use jQuery(element).autocomplete... in setSearchElement instead of jQuery('#tags') – Max Jan 7 '17 at 16:25
  • It does not make any difference the error stays. – user3748173 Jan 7 '17 at 16:34
  • try to temporarily remove afterRender binding and initialize jQuery autocomplete widget from browser console after full loading of your block. – Max Jan 7 '17 at 16:37
  • Please explain me more exactly what steps i must to do. – user3748173 Jan 7 '17 at 19:21
  • 1. after page loading you made sure that the input adresses element is present on page. 2. open browser console (F12) 3. run jQuery('#tags').autocomplete({ source: ['tag'], minLength: 2 }); in console. 4. Try to test autocomplete – Max Jan 8 '17 at 9:41

There is issue with Magento2 autocomplete in consequence of extending of base jquery-ui widget by Magento application.

More details by link: Magento 2 & JQuery.UI.Autocomplete

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.