10

Sometimes I need to know if an input field already has autocomplete bound to it. I haven't found any other way to do this other than:

$input.hasClass('ui-autocomplete-input')

Then I discovered that elements with autocomplete has an attribute like this:

<input autocomplete="off">

This however never seems to be set to on, and I can't find any documentation about this attribute.

Question: What is the best/correct way to check if autocomplete has been bound to an element?

Fractalf
  • 5,228
  • 3
  • 23
  • 26
  • 1
    Possible duplicate of [check if jQuery UI tabs have been initialized (without checking for class)](http://stackoverflow.com/questions/12393773/check-if-jquery-ui-tabs-have-been-initialized-without-checking-for-class) (the same method applies to all jQuery UI widgets). – Frédéric Hamidi Dec 03 '13 at 11:38
  • You are right in that the same method applies to all widgets, however it didn't occur to me there was some "general" way to do this until you posted the comment. I would still argue though that your comment and the answer of @Arun P Johny (thanks) still has value. – Fractalf Dec 03 '13 at 11:59

2 Answers2

19

you can also use the data property

var check = $input.data('ui-autocomplete') != undefined;
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
1

api.jqueryui.com (Autocomplete Widget)

var check = $input.autocomplete( "instance" ) !== undefined;
crashtestxxx
  • 1,405
  • 5
  • 21
  • 30