Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9275533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:36:36+00:00 2026-06-18T16:36:36+00:00

I am doing tagging with select2 I have these requirements with select2: I need

  • 0

I am doing tagging with select2

I have these requirements with select2:

  1. I need to search some tags using select2 ajax
  2. Also I need to use “tags” in select2 which Allows values that are not in the list(Ajax result).

Both the scenarios work independently. But joined together aJax values are only populated. If we type any other values not in the list then it says “no matches found”

My scenario If user type any new value which is not in the list, allow them to make up their own tag.

Any way to make this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:36:38+00:00Added an answer on June 18, 2026 at 4:36 pm

    Select2 has the function “createSearchChoice”:

    Creates a new selectable choice from user’s search term. Allows
    creation of choices not available via the query function. Useful when
    the user can create choices on the fly, eg for the ‘tagging’ usecase.

    You could achieve what you want by using:

    createSearchChoice:function(term, data) {
      if ($(data).filter(function() {
        return this.text.localeCompare(term)===0;
      }).length===0) {
        return {id:term, text:term};
      }
    },
    multiple: true
    

    Here’s a more complete answer that returns a JSON result to an ajax search, and allows tags to be created from the term, if the term returned no results:

    $(".select2").select2({
      tags: true,
      tokenSeparators: [",", " "],
      createSearchChoice: function(term, data) {
        if ($(data).filter(function() {
          return this.text.localeCompare(term) === 0;
        }).length === 0) {
          return {
            id: term,
            text: term
          };
        }
      },
      multiple: true,
      ajax: {
        url: '/path/to/results.json',
        dataType: "json",
        data: function(term, page) {
          return {
            q: term
          };
        },
        results: function(data, page) {
          return {
            results: data
          };
        }
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried doing POS tagging using openNLP POS Models on a normal Java
I have a Post model which I'm accessing through ActiveAdmin. It's also taggable using
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing some jquery animation. I have certain divs set up with an attribute of
I'm doing a search in my database. At the same time I have a
Doing some code reviews lately I came across a number of classes that have
I'm having trouble updating the DOM when doing an AJAX post using JQuery. This
After doing some initial research into using Appfabric for caching, my understanding is that
Doing some inline assembly in clang (basically guessing my way through by using various
Doing some work in javascript I have a multidimensional made up in this format

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.