lndl / select2_simple_form

Select2 inputs for SimpleForm
MIT License
25 stars 34 forks source link

select2_simple_form and cocoon gem #14

Open jsperezg opened 6 years ago

jsperezg commented 6 years ago

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?