Skip to content

Commit adfa1f2

Browse files
martynhoyermckennapsean
authored andcommitted
Fix to output checked checkboxes properly as concatenated string (dwyl#89)
* Fix to output checkbox groups properly as concatenated string * Add comments to JS
1 parent fe985ac commit adfa1f2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

form-submission-handler.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ function getFormData() {
1919
var data = {};
2020
fields.forEach(function(k){
2121
data[k] = elements[k].value;
22-
if(elements[k].type === "checkbox"){
23-
data[k] = elements[k].checked;
24-
// special case for Edge's html collection
22+
var str = ""; // declare empty string outside of loop to allow
23+
// it to be appended to for each item in the loop
24+
if(elements[k].type === "checkbox"){ // special case for Edge's html collection
25+
str = str + elements[k].checked + ", "; // take the string and append
26+
// the current checked value to
27+
// the end of it, along with
28+
// a comma and a space
29+
data[k] = str.slice(0, -2); // remove the last comma and space
30+
// from the string to make the output
31+
// prettier in the spreadsheet
2532
}else if(elements[k].length){
2633
for(var i = 0; i < elements[k].length; i++){
2734
if(elements[k].item(i).checked){
28-
data[k] = elements[k].item(i).value;
35+
str = str + elements[k].item(i).value + ", "; // same as above
36+
data[k] = str.slice(0, -2);
2937
}
3038
}
3139
}

0 commit comments

Comments
 (0)