0

I am working with http://easyautocomplete.com/. It's working fine but when I am trying to disable select on click, It's not working.

When I am trying to disable default action on onClickEvent/onChooseEvent, It's showing Uncaught TypeError: Cannot read property 'preventDefault' of undefined.

I can't figure out why event.preventDefault(); not working. I am not expert. Just for learning purpose.

var options = {
   data: [ {name: "Avionet", spec: "air", code: "47201", price: "£120"},
      {name: "Car", spec: "ground", code: "47201S", price: "£120"},
      {name: "Motorbike", spec: "ground", code: "47203", price: "£120"},
      {name: "Plain", spec: "air", code: "4721", price: "£120"},
      {name: "Train", spec: "ground", code: "47253", price: "£120"}
   ],
   getValue: "name",
   list: {
      match: {
         enabled: true
      },
      onClickEvent: function(event) {
         event.preventDefault();
      }
   },
   template: {
      type: "custom",
      method: function(value, item) {
         return '<div class="cbs-subject-name">'+ value +'</div><div class="cbs-subject-price"><span class="cbs-meta-icon cbs-meta-icon-price"></span> '+item.price+' </div><div class="cbs-subject-spec"><span class="cbs-meta">Specification:</span> '+item.spec+' </div><div class="cbs-subject-code"><span class="cbs-meta">Entry Code:</span> '+item.code+' </div>';
      }
   }
};
$("#awesomplete").easyAutocomplete(options);

Thanks for your time. :)

  • Try to use `e.stopImmediatePropagation()` from [here](https://stackoverflow.com/a/56978973/1615266). – Ivan Z Feb 02 '20 at 21:40

1 Answers1

0

The reason it's not working is that easyautocomplete calls onClickEvent() but doesn't pass anything to it, so the event parameter is null.

I don't think you can actually change what the library is doing from inside this function. It's going to go ahead and fill in the input box with the item selected by the user.

Abbeytekmd
  • 21
  • 5