[FIX] survey: submit a survey with empty date

Since rev. odoo/odoo@cd05983 it was not possible to submit a survey if a date
field was empty (trying to set `toJSON` on `null`).

The datepicker `date` function returns `null` if no date has been selected.

opw-1832381
This commit is contained in:
Martin Geubelle
2018-04-04 12:55:55 +02:00
parent b6c962e62a
commit 4fc170e0fe
+5 -3
View File
@@ -135,9 +135,11 @@ if(!the_form.length) {
for (var i=0; i < date_fields.length; i++) {
var el = date_fields[i];
var moment_date = $(el).data('DateTimePicker').date();
moment_date.toJSON = function () {
return this.clone().locale('en').format('YYYY-MM-DD');
};
if (moment_date) {
moment_date.toJSON = function () {
return this.clone().locale('en').format('YYYY-MM-DD');
};
}
var field_obj = _.findWhere(formData, {'name': el.name});
field_obj.value = JSON.parse(JSON.stringify(moment_date));
}