Giter Club home page Giter Club logo

Comments (12)

ivaynberg avatar ivaynberg commented on May 27, 2024 11

add multiple in the constructor options:

{
multiple:true,
ajax: {....}
}

from select2.

ivaynberg avatar ivaynberg commented on May 27, 2024 1

attach it to input type=hidden tag, when attached to a select tag select2 pulls the choices from the option tags.

from select2.

ivaynberg avatar ivaynberg commented on May 27, 2024

even though there is no example, the ajax part works exactly the same for multiple as it does for single.

from select2.

jaequery avatar jaequery commented on May 27, 2024

Hi, thanks for the quick replay. So i tried:

using the select html tag by select id='x' multiple

$("#x").select2({
placeholder: {title: "Search for a movie", id: ""},
minimumInputLength: 3,
ajax: {
url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json",
dataType: 'jsonp',
quietMillis: 100,
data: function (term, page) { // page is the one-based page number tracked by Select2
return {
q: term, //search term
page_limit: 10, // page size
page: page, // page number
apikey: "ju6z9mjyajq2djue3gbvv26t" // please do not use so this example keeps working
};
},
results: function (data, page) {
var more = (page * 10) < data.total; // whether or not there are more results available

            // notice we return the value of more so Select2 knows if more results can be loaded
            return {results: data.movies, more: more};
        }
    },
    formatResult: movieFormatResult, // omitted for brevity, see the source of this page
    formatSelection: movieFormatSelection // omitted for brevity, see the source of this page
});

But this doesn't work for me. Any quick guidance you can give me?
Thx!

from select2.

jaequery avatar jaequery commented on May 27, 2024

ok, so to make it work for "multiple" selects, what do i do? i've tried adding class "multiple" to the hidden input but no luck.

from select2.

jaequery avatar jaequery commented on May 27, 2024

thanks, that worked for me! but it seems the placeholder now just says [Object object].

i have:
{....
placeholder: {title: "Search for a movie", id: "s"},
....

from select2.

ivaynberg avatar ivaynberg commented on May 27, 2024

can you set up a jsfiddle so i can see exactly what you are doing? you can fork this one here:

http://jsfiddle.net/ivaynberg/seck4/10/

from select2.

jaequery avatar jaequery commented on May 27, 2024

hi, here's the updated link:

http://jsfiddle.net/5Vcfw/1/

from select2.

ivaynberg avatar ivaynberg commented on May 27, 2024

in multiselect mode only string based placeholders really make since the placeholder is not rendered as a selection (a box with an x to close it). so change it to placeholder: "Search for a movie" and it will work.

from select2.

jaequery avatar jaequery commented on May 27, 2024

perfect, thanks, and good work!

from select2.

brunoguerra avatar brunoguerra commented on May 27, 2024

wow, its really good, thanks social coders, helps a lot.

from select2.

rvazquezglez avatar rvazquezglez commented on May 27, 2024

If you are looking at this thread in 2018 and using select2 > 4.0 the input fields wont work, it should be a select https://stackoverflow.com/a/33210771/1195507

from select2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.