Skip to content

Commit 394e369

Browse files
committed
gpalf-count-only-non-blank-rows.js: Added support to calculate only non-blank rows.
1 parent 818bf08 commit 394e369

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Gravity Perks // Auto List Field // Dynamic Row Labels for List Fields
3+
* https://gravitywiz.com/documentation/gravity-forms-auto-list-field/
4+
*
5+
* Count only non-blank rows in a List field.
6+
*
7+
* Instructions:
8+
*
9+
* 1. Install this snippet with our free Custom JavaScript plugin.
10+
* https://gravitywiz.com/gravity-forms-code-chest/
11+
*/
12+
gform.addFilter('gpalf_total_rows', function (totalRows, fieldId, formId) {
13+
var $fieldWrapper = $(`#gform_${formId} #field_${formId}_${fieldId}`);
14+
if ($fieldWrapper.length === 0) {
15+
return totalRows;
16+
}
17+
18+
var $rows = $fieldWrapper.find('.gfield_list_group');
19+
if ($rows.length === 0) {
20+
return totalRows;
21+
}
22+
23+
var nonBlankCount = 0;
24+
25+
$rows.each(function () {
26+
var isNonBlank = false;
27+
28+
$(this).find('input').each(function () {
29+
if ($(this).val().trim() !== '') {
30+
isNonBlank = true;
31+
return false;
32+
}
33+
});
34+
35+
if (isNonBlank) {
36+
nonBlankCount++;
37+
}
38+
});
39+
40+
return nonBlankCount;
41+
});

0 commit comments

Comments
 (0)