[FIX] prevent crash when searching strings (addon web)
authorGéry Debongnie <ged@odoo.com>
Wed, 12 Nov 2014 14:16:55 +0000 (15:16 +0100)
committerGéry Debongnie <ged@odoo.com>
Wed, 12 Nov 2014 14:17:20 +0000 (15:17 +0100)
with the switch to moment.js, the way dates are parsed has changed,
and the autocompletion should be adapted to ignore invalid dates.

addons/web/static/src/js/search.js

index 29f4657..d2fe807 100644 (file)
@@ -1272,8 +1272,9 @@ instance.web.search.DateField = instance.web.search.Field.extend(/** @lends inst
         return instance.web.date_to_str(facetValue.get('value'));
     },
     complete: function (needle) {
-        var d = moment(needle).toDate();
-        if (!d) { return $.when(null); }
+        var m = moment(needle);
+        if (!m.isValid()) { return $.when(null); }
+        var d = m.toDate();
         var date_string = instance.web.format_value(d, this.attrs);
         var label = _.str.sprintf(_.str.escapeHTML(
             _t("Search %(field)s at: %(value)s")), {