Révision 62f5c69e
Ajouté par Assos Assos il y a presque 9 ans
drupal7/sites/all/modules/pollfield/pollfield.js | ||
---|---|---|
1 |
|
|
2 | 1 |
(function($) { |
3 |
|
|
4 | 2 |
// Re-enable form elements that are disabled for non-ajax situations. |
5 | 3 |
Drupal.behaviors.pollfield = { |
6 | 4 |
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 |
//change input name |
|
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 |
//change label for |
|
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 |
|
|
5 |
var field_name=$('input.pollfield-more-choice-button').attr('name'); |
|
6 |
var number_of_choices = 0; |
|
7 |
$('.' + field_name + '-pollfield-choices').each(function(){ |
|
8 |
number_of_choices++; |
|
9 |
}); |
|
10 |
console.log(number_of_choices); |
|
11 |
$('input.pollfield-more-choice-button').click(function(event){ |
|
12 |
var field_name=$(this).attr('name'); |
|
13 |
|
|
14 |
var number_of_choices = 0; |
|
15 |
$('.' + field_name + '-pollfield-choices').each(function(){ |
|
16 |
number_of_choices++; |
|
17 |
}); |
|
18 |
|
|
19 |
var choice_id = new String; |
|
20 |
choice_id = field_name + '-0'; |
|
21 |
var choice = $('#' + choice_id); |
|
22 |
var new_choice = choice.clone(); |
|
23 |
|
|
24 |
new_choice.children().children().children('input').val(''); |
|
25 |
new_choice.attr('id', field_name + '-' + number_of_choices); |
|
26 |
// Change input name. |
|
27 |
new_choice.children().children().children('input').each(function() { |
|
28 |
var name=String; |
|
29 |
name = $(this).attr('name'); |
|
30 |
var new_name=name.replace('[group][0]', '[group][' + number_of_choices + ']'); |
|
31 |
$(this).attr('name', new_name); |
|
32 |
var id = String; |
|
33 |
id = $(this).attr('id'); |
|
34 |
var new_id = id.replace('group-0', 'group-' + number_of_choices); |
|
35 |
$(this).attr('id', new_id); |
|
36 |
}) |
|
37 |
//change label for |
|
38 |
new_choice.children().children().children('label').each(function() { |
|
39 |
var for_name=String; |
|
40 |
for_name = $(this).attr('for'); |
|
41 |
var new_for_name = for_name.replace('group-0', 'group-' + number_of_choices); |
|
42 |
$(this).attr('for', new_for_name); |
|
43 |
}); |
|
44 |
|
|
45 |
number_of_choices++; |
|
46 |
new_choice.children().children().children('em').text(number_of_choices); |
|
47 |
$(this).before(new_choice); |
|
48 |
event.preventDefault(); |
|
49 |
}) |
|
62 | 50 |
} |
63 | 51 |
}; |
64 |
|
|
65 |
})(jQuery); |
|
52 |
})(jQuery); |
Formats disponibles : Unified diff
Weekly update of contrib modules