Fix CSV export in forms

pull/1/head
yflory 4 years ago
parent 87d04ed68a
commit c7ac75d137

@ -5,7 +5,7 @@ define([
var Export = {};
var escapeCSV = function (v) {
if (!/("|,|\n)/.test(v)) {
if (!/("|,|\n|;)/.test(v)) {
return v || '';
}
var value = '';
@ -40,7 +40,11 @@ define([
csv += escapeCSV(time);
csv += ',' + escapeCSV(user.name || Messages.anonymous);
Object.keys(form).forEach(function (key) {
if (msg[key] && typeof(msg[key]) !== "string") { console.warn(key, msg[key]); }
var type = form[key].type;
if (TYPES[type] && TYPES[type].exportCSV) {
csv += ',' + escapeCSV(TYPES[type].exportCSV(msg[key]));
return;
}
csv += ',' + escapeCSV(String(msg[key] || ''));
});
});

@ -1646,6 +1646,15 @@ define([
return h('div.cp-form-type-poll', lines);
},
exportCSV: function (answer) {
if (!answer || !answer.values) { return ''; }
var str = '';
Object.keys(answer.values).sort().forEach(function (k, i) {
if (i !== 0) { str += ';'; }
str += k.replace(';', '').replace(':', '') + ':' + answer.values[k];
});
return str;
},
icon: h('i.cptools.cptools-form-poll')
},
};

Loading…
Cancel
Save