1

I'm building some kind of indefinite filters for an app, and I'm havin this problem when I clone some selects.

The things is this selects are chained between them, trough the Chained Selects jQuery plugin.

The problem is that every time I clone the selects, the chaining stops working, and I've tryed everything, such as .live() to make it work, but it seems I'm out of luck :D

Here you have a sample of what I'm talking about, http://jsfiddle.net/7K2Eu/63/

At first, the selects chain normally, but when I clone the form, they stop working, except for the first row of selects.

Thank you!!

analogic.al
  • 739
  • 2
  • 11
  • 19
  • Your main bug is that ID's have to be unique throughout a webpage. You can't copy them and expect it to work! I'll fix your code in a bit – Khez Apr 04 '11 at 23:06
  • @Khez: You, are right, I just copied it quickly for the example. Maybe I should be using clases, wich is the best option? – analogic.al Apr 04 '11 at 23:14
  • the duplicate id's are not his problem. i think his problem is that cloning just clones the html code not the event listeners – ITroubs Apr 04 '11 at 23:23
  • I read that the dynamically created elements aren't binded to the events created in the traditional way ( $('div').clicK() ), instead I used $('div').live('click', function(){ // do something }); for attach some events on existent and future elements. [jQuery .live()](http://api.jquery.com/live/) – analogic.al Apr 04 '11 at 23:34
  • Anyway, I can't figure out how to make it work with .live() neither. – analogic.al Apr 04 '11 at 23:37

2 Answers2

2

http://jsfiddle.net/FJFFJ/1/ i think this is what you search ;-)

I figured out that when you do the clone of the template you only clone the current existing template. thus if you made some choices and therefore the chaining reduced the set of selections you clone only that reduced set of selections.

I also figured out that cloning doesn't clone the chaining.

Also I changed your duplication support so that the chaining only is being applied to the new generated items.

ITroubs
  • 11,094
  • 4
  • 27
  • 25
1

Hmz... seems a bit overly complicated...

Here's another example

Khez
  • 10,172
  • 2
  • 31
  • 51