[FIX] web: search view: don't crash when typing a date

Before this rev., it crashed when the user typed a date (actually,
the last character of a date) in the search view (e.g. in
Accounting > Customer Invoices).
This commit is contained in:
Aaron Bohy
2017-08-31 16:41:37 +02:00
parent f8694f14cc
commit 9c4eb2353c
@@ -356,8 +356,7 @@ var DateField = Field.extend(/** @lends instance.web.search.DateField# */{
var m = moment(v, t === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD');
if (!m.isValid()) { return $.when(null); }
var d = m.toDate();
var date_string = field_utils.format[this.attrs.type](d, {type: t.attrs.type});
var date_string = field_utils.format[t](m, {type: t});
var label = _.str.sprintf(_.str.escapeHTML(
_t("Search %(field)s at: %(value)s")), {
field: '<em>' + _.escape(this.attrs.string) + '</em>',
@@ -367,7 +366,7 @@ var DateField = Field.extend(/** @lends instance.web.search.DateField# */{
facet: {
category: this.attrs.string,
field: this,
values: [{label: date_string, value: d}]
values: [{label: date_string, value: m.toDate()}]
}
}]);
}