Skip to content
Snippets Groups Projects
Commit 8f8c5080 authored by Lucas Lefèvre's avatar Lucas Lefèvre
Browse files

[FIX] survey: Do not parse datetime as date

Commit 98d04248 (merged in saas-12.1) fixed a Deprecated warning by using
`field_utils.parse.date` instead of relying on
moment to parse the date.
However, a datetime question type was added in saas-12.2.
When the fix commit was forward ported, the parsing of datetime
broke as `field_utils.parse.date` can't parse a datetime.

Fix: use `field_utils.parse.datetime` if `questiontype === 'datetime'`.

Also, defining `toJSON` method is no longer necessary because
it is already done in the field_utils methods.
parent ad8a6afa
No related branches found
No related tags found
No related merge requests found
......@@ -135,19 +135,11 @@ if(!the_form.length) {
var date_fields = $form.find('div.date > input.form-control');
for (var i=0; i < date_fields.length; i++) {
var el = date_fields[i];
var moment_date = el.value !== '' ? field_utils.parse.date(el.value) : '';
if (moment_date) {
moment_date.toJSON = function () {
if ($(el).closest('.input-group.date').data('questiontype') === 'datetime') {
return this.clone().utc().format('YYYY-MM-DD hh:mm:ss');
}
else {
return this.clone().format('YYYY-MM-DD');
}
};
}
var questiontype = $(el).closest('.input-group.date').data('questiontype');
var moment_date = questiontype === 'datetime' ? field_utils.parse.datetime(el.value, null, {timezone: true}) : field_utils.parse.date(el.value);
var field_obj = _.findWhere(formData, {'name': el.name});
field_obj.value = JSON.parse(JSON.stringify(moment_date));
field_obj.value = moment_date ? moment_date.toJSON() : '';
}
$('.js_errzone').html("").hide();
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment