diff --git a/www/form/export.js b/www/form/export.js index 93f3ff6d3..0e78d171a 100644 --- a/www/form/export.js +++ b/www/form/export.js @@ -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] || '')); }); }); diff --git a/www/form/inner.js b/www/form/inner.js index 123e86d5b..8b51e2102 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -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') }, };