[FIX] website: prevent date input to fallback on today's date

The cause of the issue is that `datetimepicker('viewDate')` will return
the datetime of today by default event if the user selects nothing, to
remedy this, we now check if the user has chosen something before
storing the content of the field in `form_values`.

Step to reproduce:
- Install website_crm_partner_assign to have the "Partnership Date"
  field on res.partner.
- Install website_sale to have the "Create customer" capability on the
  website forms.
- Drag & drop a form snippet on any page
- Select "Create customer" as form action
- Add a custom field "Partnership Date"
- Submit the form without filling the Partnership Date field
- The field will be set to today's date while it should have been left
  void.

opw-3333364

closes odoo/odoo#131614

X-original-commit: 0a5668d36cc43cf346c5aecb9236d690a6694a45
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
VAN BOSSUYT Nicolas
2023-08-11 10:29:24 +02:00
parent e756e9e533
commit 144e17e5d2
@@ -336,13 +336,21 @@
// force server date format usage for existing fields
this.$el.find('.s_website_form_field:not(.s_website_form_custom)')
.find('.s_website_form_date, .s_website_form_datetime').each(function () {
const inputEl = this.querySelector('input');
// Datetimepicker('viewDate') will return `new Date()` if the
// input is empty but we want to keep the empty value
if (!inputEl.value) {
return;
}
var date = $(this).datetimepicker('viewDate').clone().locale('en');
var format = 'YYYY-MM-DD';
if ($(this).hasClass('s_website_form_datetime')) {
date = date.utc();
format = 'YYYY-MM-DD HH:mm:ss';
}
form_values[$(this).find('input').attr('name')] = date.format(format);
form_values[inputEl.getAttribute('name')] = date.format(format);
});
if (this._recaptchaLoaded) {