3

I have set up a JSFiddle to demonstrate my issue.

I have changed the way I am cloning to make it more universal, so I dont need to reuse code for different tables. Normally, for the select2 element, I would do something like this

$(".campaignType", $tr).select2({
    tags: true
});

Which means I do not need to destroy it. However, in this instance, it does not seem to work. As you can see in the fiddle, when a row is added, the select on the second row does not function. It seems to be create two spans.

Is there any way I can get this working?

Thanks

4

1 回答 1

5

The trouble comes from trying to clone the Select2 box and it loses track of it.

To solve this on the template row I do not initialise Select2. I hide the template row with .template { display: none; }. Next in the initThings method I now call the add_row method, to create the first visible row.

The add_row method can now successfully setup Select2 because it was never initialised on the cloned row.

My solution is to basically leave the template row unmodified and initialise Select2 and date picker only on the generated rows.

See fiddle: https://jsfiddle.net/vt2czgse/8/

于 2016-02-21T11:52:28.270 回答