From 00adcfa2fcce12196f97dd4b4bd7525cb1ec612e Mon Sep 17 00:00:00 2001 From: MerlinGuillaume Date: Fri, 14 Apr 2023 14:02:58 +0000 Subject: [PATCH] [FIX] web: datepicker locale, warning and hide behaviour An error is raised when trying to set the date of a note in the activities Steps to reproduce: 1. Install Notes 2. Click on the activities icon (top right of the screen) 3. Click on 'Add new note' 4. Set a date to the note 5. An error is raised Solution: Use the eventDate only if the input is set, get the locale from the getOptions function and set the datepicker warning regardless of where we get the date from Problem: `this.date` can be undefined closes odoo/odoo#118824 X-original-commit: eeae6c92bf7343d046a81ef2ae8b80443b353ad0 Signed-off-by: Julien Mougenot (jum) Signed-off-by: Guillaume Merlin (megu) --- addons/web/static/src/core/datepicker/datepicker.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/core/datepicker/datepicker.js b/addons/web/static/src/core/datepicker/datepicker.js index 3891f2442d0..a9c3d8a27c3 100644 --- a/addons/web/static/src/core/datepicker/datepicker.js +++ b/addons/web/static/src/core/datepicker/datepicker.js @@ -217,13 +217,13 @@ export class DatePicker extends Component { * @param {boolean} [params.useStatic] */ onDateChange({ eventDate, useStatic } = {}) { - let parsedDate = eventDate && this.date.locale ? momentToLuxon(eventDate).setLocale(this.date.locale): null; + const { value } = this.inputRef.el; + let parsedDate = value && eventDate ? momentToLuxon(eventDate).setLocale(this.getOptions().locale): null; if (!parsedDate) { - const { value } = this.inputRef.el; const options = this.getOptions(useStatic); parsedDate = this.parseValue(value, options)[0]; - this.state.warning = parsedDate && parsedDate > DateTime.local(); } + this.state.warning = parsedDate && parsedDate > DateTime.local(); // Always update input. // if the date is invalid, it will reset to default (= given) date. // if the input is a computed date (+5d for instance), it will put the correct date.