amsul / pickadate.js

The mobile-friendly, responsive, and lightweight jQuery date & time input picker.
http://amsul.ca/pickadate.js
MIT License
7.7k stars 1.01k forks source link

How to plus value of the date that was select? #1130

Open few2539 opened 5 years ago

few2539 commented 5 years ago

example i pick 20/01/2019 in the first one. and second date i would like to pick date between 20-25/01/2019 i used set.max but it is relative on today. Thx for helping

DanielRuf commented 5 years ago

Hi, please provide a codepen with a working example which demonstrates this so we can say what the best solution is.

few2539 commented 5 years ago
window.free_pickadate = {

        init: function () {

            var from_$input = $('#input_from').pickadate(),
                from_picker = from_$input.pickadate('picker')

            var to_$input = $('#input_to').pickadate(),
                to_picker = to_$input.pickadate('picker')

            // from_picker.set('min',true)
            from_picker.set('min', true)
            // Check if there’s a “from” or “to” date to start with.
            if (from_picker.get('value')) {
                to_picker.set('min', from_picker.get('select'))
            }

            if (to_picker.get('value')) {

                from_picker.set('max', to_picker.get('select'))

            }

            // When something is selected, update the “from” and “to” limits.

        },

        update: function () {

            var from_$input = $('#input_from').pickadate(),
                from_picker = from_$input.pickadate('picker')

            var to_$input = $('#input_to').pickadate(),
                to_picker = to_$input.pickadate('picker')

            from_picker.on('set', function (event) {
                if (event.select) {
                    to_picker.set('min', from_picker.get('select'))

                } else if ('clear' in event) {
                    to_picker.set('min', false)
                }

            })
            to_picker.on('set', function (event) {
                if (event.select) {
                    from_picker.set('max', to_picker.get('select'))
                } else if ('clear' in event) {
                    from_picker.set('max', false)
                }
            })

        },

        onReady: function () {
            $("#input_from").pickadate({
                formatSubmit: 'dd/mm/yyyy',
                // formatSubmit: '['dd','mm','yyyy']',
                hiddenName: true
            });

            $("#input_to").pickadate({

                formatSubmit: 'dd/mm/yyyy',

                hiddenName: true
            });
            window.free_pickadate.init();
            window.free_pickadate.update();

        },

    }
DanielRuf commented 5 years ago

Can you combine this with some html and provide a full codepen.com example?

few2539 commented 5 years ago

https://codepen.io/phuridate-thepnarong/pen/KJOExE

honestly sorry sir for my coming late .