[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) <jum@odoo.com>
Signed-off-by: Guillaume Merlin (megu) <megu@odoo.com>
This commit is contained in:
MerlinGuillaume
2023-04-17 18:01:34 +02:00
parent faf0f0130b
commit 00adcfa2fc
@@ -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.