[FIX] website: fix editor unable to open with filled date field

In odoo/odoo#133349 some code in website was adapted to use the new
datetime picker and luxon instead of tempusdominus and moment, but some
conversions were improperly performed causing a crash that would prevent
the website editor from opening. This commit fixes this issue and also
formats the chosen default date/datetime correctly while within the
editor.

This commit also fixes a minor issue with props validation of the
datetime picker, where we would give it an empty string instead of null
or false, causing props validation to fail in debug mode.

closes odoo/odoo#134493

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Samuel Degueldre
2023-09-12 17:16:18 +00:00
parent 654948ea63
commit 239d8c0a06
3 changed files with 8 additions and 4 deletions
@@ -1890,7 +1890,7 @@ const DatetimePickerUserValueWidget = InputUserValueWidget.extend({
*/
async setValue() {
await this._super(...arguments);
let dateTime = "";
let dateTime = null;
if (this._value) {
dateTime = DateTime.fromSeconds(parseInt(this._value))
if (!dateTime.isValid) {
@@ -35,7 +35,7 @@ const { DateTime } = luxon;
el.closest(".s_website_form_field").dataset.type === "date"
? formatDate
: formatDateTime;
el.value = format(DateTime.fromSeconds(value));
el.value = format(DateTime.fromSeconds(parseInt(value)));
}
});
}
@@ -223,7 +223,7 @@ const { DateTime } = luxon;
el.closest(".s_website_form_field").dataset.type === "date"
? formatDate
: formatDateTime;
value = format(DateTime.fromSeconds(value));
value = format(DateTime.fromSeconds(parseInt(value)));
}
el.value = value;
}
@@ -9,6 +9,7 @@ import "@website/js/editor/snippets.options";
import { unique } from "@web/core/utils/arrays";
import { _t } from "@web/core/l10n/translation";
import { renderToElement } from "@web/core/utils/render";
import { formatDate, formatDateTime } from "@web/core/l10n/dates";
let currentActionName;
@@ -1067,7 +1068,10 @@ options.registry.WebsiteFieldEditor = FieldEditor.extend({
* Select the date as value property and convert it to the right format
*/
selectValueProperty: function (previewMode, value, params) {
this.$target[0].value = value ? moment.unix(value).format(params.format) : '';
const [target] = this.$target;
const field = target.closest(".s_website_form_date, .s_website_form_datetime");
const format = field.matches(".s_website_form_date") ? formatDate : formatDateTime;
target.value = value ? format(luxon.DateTime.fromSeconds(parseInt(value))) : "";
},
/**
* Select the display of the multicheckbox field (vertical & horizontal)