Giter Site home page Giter Site logo

select2_simple_form's Issues

SyntaxError: Functions cannot be declared in a nested block in strict mode

All of my feature specs fail when using this gem, due to the error in the title.

var Select2SimpleForm = (function($) {
'use strict';

var prepareSelect2Options = function(options, $input) {
var select2Options = {};

var sanitizeInputValues = function(input) {

return input.val().replace(/[|]|"|'/g, '');

TypeError when resulting options have no HTML tags

When using this gem with an AJAX-fed select2 instance, if the text for a result doesn't contain any HTML tags, the regexp defined here in the custom matcher won't match the text, thus making the .match() call return a null value, and finally causing a TypeError to be thrown when .index is called on null.

Cannot read property 'util' of undefined

I am getting the following error when implementing a select2 with SimpleForm and this gem:

Cannot read property 'util' of undefined

This is the offending line:

var stripDiacritics = window.Select2.util.stripDiacritics;

JS error in console:

initializers.select2_simple_form.self-3b52a09c2e096725f4dfa3a398c74cc1a370d8b810a433a627531d241f5eef4a.js?body=1:42 Uncaught TypeError: Cannot read property 'util' of undefined
at prepareSelect2Options (initializers.select2_simple_form.self-3b52a09c2e096725f4dfa3a398c74cc1a370d8b810a433a627531d241f5eef4a.js?body=1:42)
at HTMLSelectElement. (initializers.select2_simple_form.self-3b52a09c2e096725f4dfa3a398c74cc1a370d8b810a433a627531d241f5eef4a.js?body=1:137)
at Function.each (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:371)
at jQuery.fn.init.each (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:138)
at HTMLDocument.initializeSelect2SimpleForm (initializers.select2_simple_form.self-3b52a09c2e096725f4dfa3a398c74cc1a370d8b810a433a627531d241f5eef4a.js?body=1:134)
at HTMLDocument.dispatch (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:5227)
at HTMLDocument.elemData.handle (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:4879)
at Object.trigger (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:5131)
at jQuery.fn.init.triggerHandler (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:5867)
at Function.ready (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:3587)

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

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
   },
   {

select2_simple_form and cocoon gem

Good morning.

I'm using select2_simple_form in combination with cocoon in order to deal with nested models. The problem that I've foud is that each time a new nested record is added select2 inputs for this row do now correctly initializes the select2 inputs. I'm trying with this code, but without much success:

$("form").on("cocoon:after-insert", function(_, row) {
    var select = row.find('.place_scheduled_tasks_chemical_product_ids').find('select');
    if (select.length) {
      Select2SimpleForm.init({allow_html: true}, select);
    }
  });

How can I use the Select2SimpleForm class in order to initialize input added dynamically to a form? Is there a place where I can find any documentation regarding to it?

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.