diff options
| author | Jason Van Malder <jvm@odoo.com> | 2020-01-22 07:45:46 +0000 |
|---|---|---|
| committer | Jason Van Malder <jvm@odoo.com> | 2020-01-24 12:48:48 +0000 |
| commit | 59a50e7628e3b02aea694b0b3cd36b2bddaae057 (patch) | |
| tree | 5968a1d4b38b6246e46173d859958a6bc4c9e9e1 /addons/survey/static/src | |
| parent | c107e983caa4089058c75ab9f0d1652ddf31dfac (diff) | |
[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>
Diffstat (limited to 'addons/survey/static/src')
| -rw-r--r-- | addons/survey/static/src/js/survey_form.js | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js index eb8ac3a95be..09cf0a21d9f 100644 --- a/addons/survey/static/src/js/survey_form.js +++ b/addons/survey/static/src/js/survey_form.js @@ -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 () { |
