diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2016-05-09 15:11:35 +0200 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2016-05-10 11:19:22 +0200 |
| commit | 50b94ef079b2fd9f4e9201ea8f977fadab109aea (patch) | |
| tree | e296a5e27e7ed2fd2b9adbae580261bdb35b3394 /addons/web/static/src/js/views/search_inputs.js | |
| parent | a775f437c872747b59777873a5c959a70789c8d1 (diff) | |
[FIX] web: search input of date
When the user searches for date (or a datetime) in the search bar, the
suggested date can become completely wrong. For example, in the French
localization where the date format is DD/MM/YYYY, the system will search
for the date MM/DD/YYYY. This is even worse when the date is not fully
written: DD/MM could be converted to MM/DD/0000, which doesn't make any
sense. This is related to the moment issue
https://github.com/moment/moment/issues/1407.
The fix is to make sure that the input date has a correct format thanks
to `parse_value`. The latter converts the date into a fixed format.
Fixes #11876
opw-676604
Diffstat (limited to 'addons/web/static/src/js/views/search_inputs.js')
| -rw-r--r-- | addons/web/static/src/js/views/search_inputs.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/addons/web/static/src/js/views/search_inputs.js b/addons/web/static/src/js/views/search_inputs.js index 9d08a537e9d..edeffd874b0 100644 --- a/addons/web/static/src/js/views/search_inputs.js +++ b/addons/web/static/src/js/views/search_inputs.js @@ -341,7 +341,17 @@ var DateField = Field.extend(/** @lends instance.web.search.DateField# */{ return time.date_to_str(facetValue.get('value')); }, complete: function (needle) { - var m = moment(needle); + // Make sure the needle has a correct format before the creation of the moment object. See + // issue https://github.com/moment/moment/issues/1407 + var t, v; + try { + t = (this.attrs && this.attrs.type === 'datetime') ? 'datetime' : 'date'; + v = formats.parse_value(needle, {'widget': t}); + } catch (e) { + return $.when(null); + } + + 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 = formats.format_value(d, this.attrs); |
