How do preload data in select2 using simple for form?

57 Views Asked by At

The select2 I use in an input as seen below:

= f.input :tag_ids, label: t("activerecord.attributes.tag.tags"), collection: Customer.all, input_html: { class: "js-example-basic-multiple js-example-responsive", multiple: true, id: "customer"}, include_blank: false

The select2 works, however it preloads the list for me for 1 second and makes it look horrible

That is why I would like to know if there is a way to preload the collection through the JQuery of select2

Passing the customer collection through JQuery and not the input

This is my javascript file

javascript:

  $("#customer").select2({
    maximumSelectionLength: 5,
    minimumInputLength: 1,
    tags: true,
    tokenSeparators: [",", " "],
    
    language: {
      maximumSelected: function (e) {
        return I18n.t("products.alert.limit_max");
      },

      inputTooShort: function (e) {
        return I18n.t("products.alert.limit_min");
      },

      noResults: function(){
        return I18n.t('products.alert.not_result_found');
      }
    },
  });
0

There are 0 best solutions below