Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript conditional within function datecalendar

Morning!

I have this question:

This function:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 calendar_arrival.datepicker({
    beforeShow: function () {
      $('#ui-datepicker-div').removeClass('departure').addClass('arrival');
    },
    minDate: mindate,
    dateFormat: format,
    closeText: "Close",
    currentText: "",
    firstDay: 0,
    nextText: " >>",
    prevText: "<< ",
    monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
    monthNamesShort: monthNamesShortArray,
    dayNames: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
    dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
    dayNamesMin: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
    isRTL: false,
    onClose: function () {
      var minDate = calendar_arrival.datepicker('getDate');
      if (minDate) {
        minDate.setDate(minDate.getDate() + 2);
      };
      calendar_departure.datepicker('option', 'minDate', minDate || 1).on('focus', function () {
        $(this).trigger('blur');
      }); // Date + 1 or tomorrow by default

      if (convertDates) {
        populateCalendar(calendar_arrival);
        populateCalendar(calendar_departure);
      }
    }

Has 3 parameters that I would like to change depending the language:

monthNames

dayNames

dayNamesShort

dayNamesMin

I’m trying to use a conditional for example:

  if ($('html').hasClass('smrt-es')) {

var monthNames = ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"];

  } else if ($('html').hasClass('smrt-en')) {

var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

  }

But not works… gives and error in the console.

I’m wondering if any of you has a quick solution.

Thanks so much!
Rob

>Solution :

You can try declaring the monthNames as default outside of the conditional, and then update its value based on the language:

var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

if ($('html').hasClass('smrt-es')) {
  monthNames = ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"];
}

calendar_arrival.datepicker({
  // ...
  monthNames: monthNames,
  // ...
});

Do the same for the other parameters dayNames, dayNamesShort, and dayNamesMin.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading