[FIX] survey: better datetime picker & fix date format issues
Issue
- Install Surveys & Website
- Create a survey with a datetime question
- Install Spanish lang & set it up on website as the only language
- Surveys > Your survey > Test
Traceback
Cause
There is a format mismatch because of field_utils.format.datetime
but it's needed for timezone offsets.
Solution
Format the field_utils.format.datetime result's into
the datetimepicker format.
I re-organized this part because it was a bit confusing and
it handles error now.
OPW-2167397
closes odoo/odoo#43912
X-original-commit: b368b1db4a998a2369185218fe19fb84874f77ab
Signed-off-by: Jason Van Malder (jvm) <jvm@odoo.com>
This commit is contained in:
@@ -2207,6 +2207,20 @@ msgstr ""
|
||||
msgid "The badge for each survey should be unique!"
|
||||
msgstr ""
|
||||
|
||||
#. module: survey
|
||||
#. openerp-web
|
||||
#: code:addons/survey/static/src/js/survey.js:0
|
||||
#, python-format
|
||||
msgid "The date you selected is greater than the maximum date: "
|
||||
msgstr ""
|
||||
|
||||
#. module: survey
|
||||
#. openerp-web
|
||||
#: code:addons/survey/static/src/js/survey.js:0
|
||||
#, python-format
|
||||
msgid "The date you selected is lower than the minimum date: "
|
||||
msgstr ""
|
||||
|
||||
#. module: survey
|
||||
#: model:ir.model.fields,help:survey.field_survey_survey__description
|
||||
msgid ""
|
||||
|
||||
@@ -5,9 +5,11 @@ var field_utils = require('web.field_utils');
|
||||
var publicWidget = require('web.public.widget');
|
||||
var time = require('web.time');
|
||||
var core = require('web.core');
|
||||
var _t = core._t;
|
||||
var Dialog = require('web.Dialog');
|
||||
var dom = require('web.dom');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
|
||||
selector: '.o_survey_form',
|
||||
events: {
|
||||
@@ -611,12 +613,9 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
|
||||
* Initialize datetimepicker in correct format and with constraints
|
||||
*/
|
||||
_initDateTimePicker: function ($dateGroup) {
|
||||
var disabledDates = [];
|
||||
|
||||
var minDateData = $dateGroup.data('mindate');
|
||||
var minDate = minDateData ? this._formatDateTime(minDateData) : moment({ y: 1900 });
|
||||
var maxDateData = $dateGroup.data('maxdate');
|
||||
var maxDate = maxDateData ? this._formatDateTime(maxDateData) : moment().add(200, "y");
|
||||
var disabledDates = []
|
||||
var minDateData = $dateGroup.data('mindate')
|
||||
var maxDateData = $dateGroup.data('maxdate')
|
||||
|
||||
var datetimepickerFormat = time.getLangDateFormat();
|
||||
if ($dateGroup.find('input').data('questionType') === 'datetime') {
|
||||
@@ -628,13 +627,20 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
|
||||
disabledDates = [minDate, maxDate];
|
||||
}
|
||||
|
||||
var minDate = minDateData
|
||||
? this._formatDateTime(minDateData, datetimepickerFormat)
|
||||
: moment({ y: 1900 });
|
||||
var maxDate = maxDateData
|
||||
? this._formatDateTime(maxDateData, datetimepickerFormat)
|
||||
: moment().add(200, "y");
|
||||
|
||||
$dateGroup.datetimepicker({
|
||||
format : datetimepickerFormat,
|
||||
minDate: minDate,
|
||||
maxDate: maxDate,
|
||||
disabledDates: disabledDates,
|
||||
useCurrent: false,
|
||||
viewDate: moment(new Date()).hours(0).minutes(0).seconds(0).milliseconds(0),
|
||||
viewDate: moment(new Date()).hours(minDate.hours()).minutes(minDate.minutes()).seconds(minDate.seconds()).milliseconds(minDate.milliseconds()),
|
||||
calendarWeeks: true,
|
||||
icons: {
|
||||
time: 'fa fa-clock-o',
|
||||
@@ -647,13 +653,22 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
|
||||
locale : moment.locale(),
|
||||
allowInputToggle: true,
|
||||
});
|
||||
$dateGroup.on('error.datetimepicker', function () {
|
||||
$dateGroup.on('error.datetimepicker', function (err) {
|
||||
if (err.date) {
|
||||
if (err.date < minDate) {
|
||||
Dialog.alert(this, _t('The date you selected is lower than the minimum date: ') + minDate.format(datetimepickerFormat));
|
||||
}
|
||||
|
||||
if (err.date > maxDate) {
|
||||
Dialog.alert(this, _t('The date you selected is greater than the maximum date: ') + maxDate.format(datetimepickerFormat));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
|
||||
_formatDateTime: function (datetimeValue) {
|
||||
return field_utils.format.datetime(moment(datetimeValue), null, {timezone: true});
|
||||
_formatDateTime: function (datetimeValue, format){
|
||||
return moment(field_utils.format.datetime(moment(datetimeValue), null, {timezone: true}), format);
|
||||
},
|
||||
|
||||
_initResultWidget: function () {
|
||||
|
||||
Reference in New Issue
Block a user