nazar-pc / PickMeUp

Really simple, powerful, customizable and lightweight standalone datepicker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to disable the Selection?

santhoshsvkmm opened this issue · comments

I have created a date range picker using pickmeup where in have options like custom , till date and last year.
when i select till date i have removed the selection in the calendar but after clicking the next option its comes. this is my code below.......

$(function (e) {
    $('.calendars').pickmeup({
        flat: true,
        mode: 'range',
        calendars: 3
    });
    var selecteddate = [];
    $('.calendars .pickmeup .pmu-instance').on('click', '.pmu-days .pmu-button', function () {
        $('.from-date').val('');
        $('.to-date').val('');
        var dayparent = $(this).parent();
        var monthparent = dayparent.parent();
        var nav = monthparent.find('nav');
        var monthformat = nav.find('.pmu-month').html();
        var day = $(this).html();
        var monthary = monthformat.split(/[\s,]+/);
        var months = [
            'January', 'February', 'March', 'April', 'May',
            'June', 'July', 'August', 'September',
            'October', 'November', 'December'
        ];
        var month = monthary[0];
        var year = monthary[1];
        for (var i = 0; i <= months.length; i++) {
            if (month === months[i]) {
                var monthnumber = i + 1;
            }
        }
        var formateddate = [monthnumber, day, year].join('/');
        selecteddate.push(formateddate);
        if (selecteddate.length === 2) {
            var fromdate = moment(selecteddate[0]).format('MM/DD/YYYY');
            var todate = moment(selecteddate[1]).format('MM/DD/YYYY');
            console.log(fromdate);
            // $('.from-date').val(fromdate);
            // $('.to-date').val(todate);
            selecteddate.length = 0;
            if (new Date(fromdate) > new Date(todate)) {
                $('.from-date').val(todate);
                $('.to-date').val(fromdate);

            } else if (new Date(fromdate) < new Date(todate)) {
                $('.from-date').val(fromdate);
                $('.to-date').val(todate);
            }

        } else {
            // selecteddate.length = 0;

        }
    });
    // $('.pmu-button').on('click', function () {


    // 	})
    $('#calendar-control').on('change', function () {
        if (this.value === 'custom') {
            $('.from-date').val('');
            $('.to-date').val('');
            $('.disable-calendar').hide();
        } else if (this.value === 'lastyear') {
            console.log('lastyear');
            var date = new Date(),
                y = date.getFullYear() - 1,
                m = date.getMonth();
            var firstDay = new Date(y, 0, 1);
            var lastDay = new Date(y, 12, 0);
            var formatedfromdate = new Date((firstDay.getMonth() + 1) + '/' + firstDay.getDate() + '/' + firstDay.getFullYear());
            var formatedtodate = new Date((lastDay.getMonth() + 1) + '/' + lastDay.getDate() + '/' + lastDay.getFullYear());
            var formatedmomentfromdate = moment(formatedfromdate).format('MM/DD/YYYY');
            var formatedmomenttodate = moment(formatedtodate).format('MM/DD/YYYY');
            $('.from-date').val(formatedmomentfromdate);
            $('.to-date').val(formatedmomenttodate)
            $('.disable-calendar').show();
            $('.pmu-button').removeClass('pmu-selected')
        } else if (this.value === 'lastmonth') {
            var date = new Date(),
                y = date.getFullYear(),
                m = date.getMonth() - 1;
            var firstDay = new Date(y, m, 1);
            var lastDay = new Date(y, m + 1, 0);
            var formatedfromdate = new Date((firstDay.getMonth() + 1) + '/' + firstDay.getDate() + '/' + firstDay.getFullYear());
            var formatedtodate = new Date((lastDay.getMonth() + 1) + '/' + lastDay.getDate() + '/' + lastDay.getFullYear());
            var formatedmomentfromdate = moment(formatedfromdate).format('MM/DD/YYYY');
            var formatedmomenttodate = moment(formatedtodate).format('MM/DD/YYYY');
            $('.from-date').val(formatedmomentfromdate);
            $('.to-date').val(formatedmomenttodate)
            $('.disable-calendar').show();
            $('.pmu-button').removeClass('pmu-selected')
        } else if (this.value === 'tilldate') {
            var date = new Date(),
                y = date.getFullYear(),
                m = date.getMonth();
            var firstDay = new Date(y, 0, 1);
            var lastDay = new Date();
            var formatedfromdate = new Date((firstDay.getMonth() + 1) + '/' + firstDay.getDate() + '/' + firstDay.getFullYear());
            var formatedtodate = new Date((lastDay.getMonth() + 1) + '/' + lastDay.getDate() + '/' + lastDay.getFullYear());
            var formatedmomentfromdate = moment(formatedfromdate).format('MM/DD/YYYY');
            var formatedmomenttodate = moment(formatedtodate).format('MM/DD/YYYY');
            $('.from-date').val(formatedmomentfromdate);
            $('.to-date').val(formatedmomenttodate)
            $('.disable-calendar').show();
            $('.pmu-button').removeClass('pmu-selected')
        }
    })
    if (!$(e.target).is('.collapse')) {
        $('#demo').removeClass('show');
    }

    $('.disable-calendar').on('click', function () {
        $(this).hide();
        $('.from-date').val('');
        $('.to-date').val('');
        $('#calendar-control').val('custom');
        $('.pmu-button').removeClass('pmu-selected')

    })

});

First of all, make sure to read a readme, there is a description of all options and events that can be used, also browse past questions here on GitHub, some of them contain code examples with solutions.

If those didn't help, it would be easier for me to figure out what you need if you can write a steps you are trying to do and at which point expectation doesn't meet actual behavior. Don't expect me to run that large piece of code, I have a lot of other things to do.