{"id":6468,"date":"2014-04-18T06:51:58","date_gmt":"2014-04-18T06:51:58","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/how-can-i-make-this-link-clickable-in-jquery-ui-autocomplete-uncaught-typeerror-collection-of-common-programming-errors-2\/"},"modified":"2014-04-18T06:51:58","modified_gmt":"2014-04-18T06:51:58","slug":"how-can-i-make-this-link-clickable-in-jquery-ui-autocomplete-uncaught-typeerror-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/how-can-i-make-this-link-clickable-in-jquery-ui-autocomplete-uncaught-typeerror-collection-of-common-programming-errors-2\/","title":{"rendered":"How can I make this link clickable in JQuery UI Autocomplete? Uncaught TypeError-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to use the Jquery UI autocomplete plugin, and i&#8217;d like to render some html in the suggest box, with clickable links. The html seems to render ok, however when I click the links, they don&#8217;t work and I get in my developer log:<\/p>\n<pre><code>jquery-ui.min.js:239Uncaught TypeError: Cannot call method 'data' of null\n\nUncaught TypeError: Cannot call method 'data' of null\na.widget._create.menu.a.addClass.appendTo.mousedown.menu.selectedjquery-ui.min.js:239\na.Widget._triggerjquery-ui.min.js:23\na.widget.selectjquery-ui.min.js:252\na.widget._createjquery-ui.min.js:247\nf.event.handlejquery.min.js:17\nf.event.add.k.i.handle.k jquery.min.js:16\n<\/code><\/pre>\n<p>I&#8217;m using the following code in the HTML and Jquery side, the syntax is Haml as its in Rails. In the first script tag, I just define a template that I then render with Underscore.js.<\/p>\n<p>This question seems to reference a similar problem, but I don&#8217;t understand the answer <code>\"I think autocomplete uses an for the element that provides the click event. In that case, you'll need to unset that click handler\"<\/code><\/p>\n<p>I&#8217;d appreciate any guidance! Its been 2 days I&#8217;ve been stuck on this. Thanks!<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/zNrwp.png\" \/><\/p>\n<pre><code>= text_field_tag :search, nil, :class =&gt; \"jq_watermark\", :id =&gt; \"product-search-input\", :title =&gt; \"Keywords, Tags, Items, SKU...\"\n\n%script(type=\"text\/html\" id=\"product-autocomplete-result-template\")\n  .cell.img\n    %img(src='{{ main_image_thumb }}')\n  .cell\n    %h2= link_to '{{ label }}', CGI::unescape(product_path('{{ id }}'))\n    .clear\n    = link_to '{{ customer_count }} people have this', '#'\n    %span Rating {{ rating }}\n    %div{:id =&gt; \"stars-wrapper-{{ id }}\"}\n      %select= options_for_select([1, 2, 3, 4, 5])\n    %a(href='http:\/\/www.google.com') \n      Click Me\n  .cell \n    = link_to \"I have this\", '#', :class =&gt; \"button\"\n    = link_to \"I want this\", '#', :class =&gt; \"button\"\n\n:javascript\n  $(document).ready(function(){\n\n    $.ui.autocomplete.prototype._renderItem = function( ul, item ) {\n      var template = $('#product-autocomplete-result-template').html();\n      var parsed_template = _.template(template, item);\n      var target_option = 'value=\"' + item.rating + '\"';    \/\/ do simple string replace to select option, as I can't get Jquery\n      var selected_option = target_option + ' selected=\"selected\"';\n      var autocomplete_html = parsed_template.replace(target_option, selected_option);\n      var returnVal = $( \"<\/code><\/pre>\n<pre>\" )\n        .data( \"item.autocomplete\", item )\n        .append('' + autocomplete_html+'')\n        .appendTo( ul );\n      $(\"#stars-wrapper-\"+item.id).stars({ inputType: \"select\", disabled: true });\n      return returnVal;\n    };\n\n    $('#product-search-input').autocomplete({\n          delay: 50,\n      source: function(request, response) {\n        $.ajax({\n          url: \"#{search_products_path}\",\n          dataType: 'json',\n          data: { term: request.term },\n          success: function(data) {\n            if (data.length &lt; 1) {\n              console.log(\"Juuusstt right\");\n              \/\/ show submit button\n            } else {\n              console.log(\"Too long\");\n              \/\/ hide submit button\n            }\n            response(data);\n          }\n        });\n      },\n      select: function( event, ui ) {\n        console.log( ui.item ?\n          \"Selected: \" + ui.item.label :\n          \"Nothing selected, input was \" + this.value);\n      }\n   })\n  });\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to use the Jquery UI autocomplete plugin, and i&#8217;d like to render some html in the suggest box, with clickable links. The html seems to render ok, however when I click the links, they don&#8217;t work and I get in my developer log: jquery-ui.min.js:239Uncaught TypeError: Cannot call method &#8216;data&#8217; of null Uncaught TypeError: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6468","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6468"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6468\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}