Untitled

 avatar
unknown
plain_text
5 months ago
1.9 kB
4
Indexable
var currDate = new Date();
var pDays, pDaysShort, pDaysMin, pMonths, pMonthsShort;

pDays = Globalize.culture(Globalize.cultureSelector).calendar.days.names;
pDays.push(pDays[0]);
pDaysShort = Globalize.culture(Globalize.cultureSelector).calendar.days.namesAbbr;
pDaysShort.push(pDaysShort[0]);
pDaysMin = pDaysShort;

pMonths = Globalize.culture(Globalize.cultureSelector).calendar.months.names;
pMonths = pMonths.slice(0, pMonths.length - 1);
pMonthsShort = Globalize.culture(Globalize.cultureSelector).calendar.months.namesAbbr;
pMonthsShort = pMonthsShort.slice(0, pMonthsShort.length - 1);

$(elem).DatePicker({
    format: "dd-m-Y",
    date: $(elem).val(),
    current: $(elem).val(),
    starts: 1,
    mode: "range",
    locale: { days: pDays, daysShort: pDaysShort, daysMin: pDaysMin, months: pMonths, monthsShort: pMonthsShort, weekMin: 'sm' },
    onBeforeShow: function () {
        $(elem).DatePickerSetDate($(elem).val(), true);
    },
    onChange: function (formated, dates) {
        $(elem).focus();
        let formated_dates = formated.map(date => {
            // Extract the day, month, and year parts
            let day = date.slice(0, 2); // Take the first two digits as the day
            let month = date.slice(5, 7); // Take the month from the correct position
            let year = date.slice(8); // Take the year

            // Return the correctly formatted date
            return `${day}-${month}-${year}`;
        });

        $(elem).val(formated_dates);

        var e = jQuery.Event("keypress");
        e.which = 13;
        e.keyCode = 13;
        $(elem).trigger(e);
    }
});

$(elem).on('keydown', function (event) {
    // Check if the 'Escape' key was pressed
    if (event.key === 'Escape' || event.keyCode === 27) {
        $(this).DatePickerHide(); // Hide the element using jQuery's hide method
    }
});
Editor is loading...
Leave a Comment