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

Stopped working for list of entries with the same id #206

Open
mhenrixon opened this issue Jan 15, 2023 · 0 comments
Open

Stopped working for list of entries with the same id #206

mhenrixon opened this issue Jan 15, 2023 · 0 comments

Comments

@mhenrixon
Copy link

The following code used to work:

$('[data-select-products]').each(function() {
  var $el;
  $el = $(this);
  return $el.select2({
    theme: 'bootstrap',
    width: null,
    containerCssClass: ':all:',
    minimumInputLength: 2,
    ajax: {
      url: '/admin/shop/products',
      delay: 600,
      dataType: 'json',
      data: function(params) {
        return {
          search: params.term,
          page_limit: 10,
          reject_ids: $el.data('reject-ids')
        };
      },
      processResults: function(data) {
        var i, len, p, ref, results, text;
        results = [];
        ref = data.products;
        for (i = 0, len = ref.length; i < len; i++) {
          p = ref[i];
          text = p.reference;
          results.push({
            id: p.id,
            text: text
          });
        }
        return {
          results: results
        };
      }
    }
  });
});

For the following HTML:

= form_for [:admin, :shop, @product, product_relation], html: {class: '', data: {remote: true}} do |f|
    .form-group.row
      .col-md-6
        - if product_relation.new_record?
          = f.hidden_field :relation_id
          = f.select :related_product_id, [], {}, id: "product_relation_related_product_id", data: { select_products: true, reject_ids: product_ids}, class: 'form-control'

As it is now after upgrading select2-rails and jQuery dependencies it only marks the last one for select2. Any ideas on what I need to change to make it work for the first x records and not only the last? It used to work at some point :)

Haven't used jQuery in years so baffled, that said I am in the process of upgrading all our dependencies so figured something in the usage changed.

@mhenrixon mhenrixon changed the title Stopped working Stopped working for list of entries with the same id Jan 15, 2023
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

1 participant