From 7d1c05216b318ea2a6bc3d991ff8aad6ea596e91 Mon Sep 17 00:00:00 2001 From: David Beguin Date: Mon, 26 Nov 2018 17:04:31 +0100 Subject: [PATCH] [FIX] survey : apply min and max date configuration in survey page The configuration of question of type 'Date' was not used at all. The datetimepicker configuration was hardcoded and did not take into account the configuration of questions of type 'Date'. Now, for each datetimepicker, we use the corresponding configuration for min and max date. Task ID : 1912194 Closes PR #28966 --- addons/survey/static/src/js/survey.js | 36 +++++++++++++----------- addons/survey/views/survey_templates.xml | 4 ++- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/addons/survey/static/src/js/survey.js b/addons/survey/static/src/js/survey.js index 6542f63a3dc..16def6107d2 100644 --- a/addons/survey/static/src/js/survey.js +++ b/addons/survey/static/src/js/survey.js @@ -183,22 +183,26 @@ if(!the_form.length) { // frontend does not load moment locale at all. // so wait until DOM ready with locale then init datetimepicker ready_with_locale.then(function(){ - $('.input-group.date').datetimepicker({ - format : time.getLangDateFormat(), - minDate: moment({ y: 1900 }), - maxDate: moment().add(200, "y"), - calendarWeeks: true, - icons: { - time: 'fa fa-clock-o', - date: 'fa fa-calendar', - next: 'fa fa-chevron-right', - previous: 'fa fa-chevron-left', - up: 'fa fa-chevron-up', - down: 'fa fa-chevron-down', - }, - locale : moment.locale(), - allowInputToggle: true, - keyBinds: null, + _.each($('.input-group.date'), function(date_field){ + var minDate = $(date_field).data('mindate') || moment({ y: 1900 }); + var maxDate = $(date_field).data('maxdate') || moment().add(200, "y"); + $('#' + date_field.id).datetimepicker({ + format : time.getLangDateFormat(), + minDate: minDate, + maxDate: maxDate, + calendarWeeks: true, + icons: { + time: 'fa fa-clock-o', + date: 'fa fa-calendar', + next: 'fa fa-chevron-right', + previous: 'fa fa-chevron-left', + up: 'fa fa-chevron-up', + down: 'fa fa-chevron-down', + }, + locale : moment.locale(), + allowInputToggle: true, + keyBinds: null, + }); }); // Launch prefilling prefill(); diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index 0375b26626f..9efe5426187 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -238,7 +238,9 @@