initial commit
[emels.git] / emels / static / js / formset.js
1 (function($) {
2     $(function() {
3
4
5 function cloneMore(selector, type) {
6     var newElement = $(selector).clone(true);
7     var total = $('#id_' + type + '-TOTAL_FORMS').val();
8     newElement.find(':input').each(function() {
9         var name = $(this).attr('name').replace('__prefix__', total);
10         var id = 'id_' + name;
11         $(this).attr({'name': name, 'id': id});
12     });
13     newElement.find('label').each(function() {
14         var newFor = $(this).attr('for').replace('__prefix__', total);
15         $(this).attr('for', newFor);
16     });
17     newElement.attr({'style': '', 'id': ''});
18     total++;
19     $('#id_' + type + '-TOTAL_FORMS').val(total);
20     $(selector).before(newElement);
21 }
22
23
24
25             $('.add_more').click(function() {
26                 cloneMore($(this).data('selector'), $(this).data('prefix'));
27             });
28
29     });
30 })(jQuery);