Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle data that does not have id or text data fields #10

Open
cdesch opened this issue Feb 8, 2018 · 1 comment
Open

How to handle data that does not have id or text data fields #10

cdesch opened this issue Feb 8, 2018 · 1 comment

Comments

@cdesch
Copy link

cdesch commented Feb 8, 2018

How do I handle with select2 data that does not have id and text fields?

Data like this will work:

 var data = [
    {
      id: 0,
      text: 'enhancement'
    },
    {
      id: 1,
      text: 'bug'
    },
    {
      id: 2,
      text: 'duplicate'
    },
    {
      id: 3,
      text: 'invalid'
    },
    {
      id: 4,
      text: 'wontfix'
    }
  ];
  $('#request_for_proposal_geo_path_counties').select2({
    theme: "bootstrap",
    data:  data
  });

But data like this won't:

var data = [
   {
     "fips": "02",
     "name": "Alaska",
     "zip_codes": [],
     "counties": [],
     "population_0": 752680,
     "population_5": 698356,
     "population_18": 565916,
     "population_21": 534794
   },
   {
@lndl
Copy link
Owner

lndl commented Feb 9, 2018

Hi @cdesch,

Unfortunately, there is nothing to custom the shape of the results. It should have some kind of function hook in this place: https://github.com/lndl/select2_simple_form/blob/master/app/assets/javascripts/select2_simple_form/initializers.select2_simple_form.js#L89

If you want, you can do that change and I will merge it thankfully!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants