1 |
85ad3d82
|
Assos Assos
|
|
2 |
|
|
(function($) {
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
Drupal.behaviors.pollfield = {
|
6 |
|
|
attach: function() {
|
7 |
|
|
var field_name=$('input.pollfield-more-choice-button').attr('name');
|
8 |
|
|
var number_of_choices = 0;
|
9 |
|
|
$('.'+field_name+'-pollfield-choices').each(function(){
|
10 |
|
|
number_of_choices++;
|
11 |
|
|
});
|
12 |
|
|
console.log(number_of_choices);
|
13 |
|
|
$('input.pollfield-more-choice-button').click(function(event){
|
14 |
|
|
var field_name=$(this).attr('name');
|
15 |
|
|
|
16 |
|
|
var number_of_choices = 0;
|
17 |
|
|
$('.'+field_name+'-pollfield-choices').each(function(){
|
18 |
|
|
number_of_choices++;
|
19 |
|
|
});
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
var choice_id = new String;
|
23 |
|
|
choice_id = field_name+'-0';
|
24 |
|
|
var choice = $('#'+choice_id);
|
25 |
|
|
var new_choice = choice.clone();
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
new_choice.children().children().children('input').val('');
|
29 |
|
|
new_choice.attr('id',field_name+'-'+number_of_choices);
|
30 |
|
|
|
31 |
|
|
new_choice.children().children().children('input').each(function(){
|
32 |
|
|
var name=String;
|
33 |
|
|
name = $(this).attr('name');
|
34 |
|
|
var new_name=name.replace('[group][0]','[group]['+number_of_choices+']');
|
35 |
|
|
$(this).attr('name',new_name);
|
36 |
|
|
var id=String;
|
37 |
|
|
id=$(this).attr('id');
|
38 |
|
|
var new_id = id.replace('group-0','group-'+number_of_choices);
|
39 |
|
|
$(this).attr('id',new_id);
|
40 |
|
|
|
41 |
|
|
})
|
42 |
|
|
|
43 |
|
|
new_choice.children().children().children('label').each(function(){
|
44 |
|
|
var for_name=String;
|
45 |
|
|
for_name = $(this).attr('for');
|
46 |
|
|
var new_for_name=for_name.replace('group-0','group-'+number_of_choices);
|
47 |
|
|
$(this).attr('for',new_for_name);
|
48 |
|
|
|
49 |
|
|
})
|
50 |
|
|
|
51 |
|
|
number_of_choices++;
|
52 |
|
|
new_choice.children().children().children('em').text(number_of_choices);
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
$(this).before(new_choice);
|
56 |
|
|
|
57 |
|
|
event.preventDefault();
|
58 |
|
|
|
59 |
|
|
})
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
}
|
63 |
|
|
};
|
64 |
|
|
|
65 |
|
|
})(jQuery); |