0

I want to add multiple array in autocomplete. I have added aTags but how can I add bTags?

var aTags = ["ask", "always", "all", "alright", "one", "foo", "blackberry", "tweet", "force9", "westerners", "sport"];

var bTags = ["aaaaaaa", "bbbbbbbb", "ccccccc", "ddddddddd"];


$("#tags").autocomplete({
  source: aTags,
  response: function(e, result) {
    if (!result.content.length) {
      console.log('No matches!');
      jQuery('#messag').html("Not match...").show();
    } else {
      jQuery('#messag').hide();
    }
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />
<input type='text' title='Tags' id='tags' />
<span id="messag"></span>

Jsfiddle demo

0

1 Answer 1

1

You can use the Array.prototype.concat() function to achieve this.

You would need to change the source: aTags to source: aTags.concat(bTags)

var aTags = ["ask", "always", "all", "alright", "one", "foo", "blackberry", "tweet", "force9", "westerners", "sport"];

var bTags = ["aaaaaaa", "bbbbbbbb", "ccccccc", "ddddddddd"];


$("#tags").autocomplete({
  source: aTags.concat(bTags),
  response: function(e, result) {
    if (!result.content.length) {
      console.log('No matches!');
      jQuery('#messag').html("Not match...").show();
    } else {
      jQuery('#messag').hide();
    }
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />
<input type='text' title='Tags' id='tags' />
<span id="messag"></span>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.