0

Background: I'm trying to have 2-3 tabs which the user can select from (in an HTML page). The first tab is based on the sniffed language of the browser, and the user will have the possibility to also pick English or Norwegian.

enter image description here

Technical part: I create three calendars $('#datetimepicker*LANGUAGE*'),

$(function() {
  $('#datetimepickerEN').datetimepicker({
    format: 'YYYY-MM-DD HH:mm',
    formatTime: 'HH:mm',
    step:15,
    startDate: moment().toDate(),
    minDate: moment().toDate(),
    maxDate: moment().add(20, "days").toDate(),
  });
  $.datetimepicker.setDateFormatter({
    parseDate: function(date, format) {
      var d = moment(date, format);
      return d.isValid() ? d.toDate() : false;
    },
    formatDate: function(date, format) {
      return moment(date).format(format);
    },
  });
});$(function() {
  $('#datetimepickerPL').datetimepicker({
    format: 'YYYY-MM-DD HH:mm',
    formatTime: 'HH:mm',
    step:15,
    startDate: moment().toDate(),
    minDate: moment().toDate(),
    maxDate: moment().add(20, "days").toDate(),
  });
  $.datetimepicker.setDateFormatter({
    parseDate: function(date, format) {
      var d = moment(date, format);
      return d.isValid() ? d.toDate() : false;
    },
    formatDate: function(date, format) {
      return moment(date).format(format);
    },
  });
});
$.datetimepicker.setLocale('pl');

each attached to its correspondig input element

<input type="text" autocomplete="off" name="date" id="datetimepicker*LANGUAGE*" />

but upon setting the language, for example

$.datetimepicker.setLocale('pl');

the language of all three calendars are changed, which is logical because apparently I set the langue of only one instance $.datetimepicker. The question is now as to how I can address this issue. Do I need 3 different instances? (if yes, how?)

7segment
  • 33
  • 6
  • Seeing as https://github.com/xdan/datetimepicker#datetimepicker says, _"!!! The latest version of the options 'lang' obsolete. The language setting is now global. !!!"_, that might not be possible any more in current versions. (Unless it still lets you use `lang` as an option alternatively, you'd have to test it.) – CBroe Feb 28 '22 at 07:45
  • A hacky workaround might be to use iFrames - a different one for each language?! – Professor Abronsius Feb 28 '22 at 10:18
  • Thank you both. I used this for setting the language: $.datetimepicker.setLocale('$datePickerLanguage'); where $datePickerLanguage is set differently for each tab (for example 'EN', 'PL', 'ZH' ,...) The question still remains as to whether it is possible at all to have several instances of the same jquery "object". – 7segment Mar 01 '22 at 16:22

0 Answers0