Skip to content

Commit fa4be61

Browse files
jdmoranijdmorani
authored andcommitted
added support for removing duplicates if only the first occurrence of a field should be displayed
1 parent 20b6261 commit fa4be61

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

lib/generators/nested_form/templates/nested_form.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ $(function() {
1212
if($(this[i]).attr('class') == 'remove_nested_fields')
1313
this[i] = $(this[i]).closest('.fields').siblings('a.add_nested_fields')[0];
1414

15-
var add_btn = $(this[i]);;
16-
var parent = $(this[i]).parent('.fields');
17-
var siblings = $(this[i]).siblings('.fields');
18-
var children = add_btn.parents('.fields').children('.fields').children('a.add_nested_fields');
19-
20-
var limit = this[i].getAttribute('limit');
21-
var section_label = this[i].getAttribute('section');
15+
var add_btn = $(this[i]);
16+
var siblings = $(this[i]).siblings('.fields');
17+
var children = add_btn.parents('.fields').children('.fields').children('a.add_nested_fields');
18+
19+
var limit = this[i].getAttribute('limit');
20+
var section_label = this[i].getAttribute('section');
2221

2322
if($(children).size() > 0)
2423
$(children).update_labels_and_buttons();
@@ -34,11 +33,18 @@ $(function() {
3433

3534
for(var j=1;j<siblings.size();j++)
3635
{
36+
//update section
3737
if(section_label)
3838
{
3939
var label = (j > 1 ? (section_label + " " + j) : section_label);
4040
$(siblings[j]).children('.section').html(label);
4141
}
42+
43+
//remove duplicate fields if only the first occurence should be displayed
44+
$(siblings[j]).children('.input').each(function () {
45+
if($(this).attr('visible') == 'show_first_only')
46+
$(this).hide();
47+
});
4248
}
4349
}
4450
}
@@ -79,7 +85,7 @@ $(function() {
7985
content = content.replace(regexp, new_id);
8086

8187
var divToAdd = $(this).before(content);
82-
console.log($(divToAdd).prev())
88+
8389
$(divToAdd).prev().hide();
8490
$(divToAdd).prev().fadeIn(300, function(){
8591
$(divToAdd).prev().show();

0 commit comments

Comments
 (0)