PitPik / tinyDatePicker

NEW: Tiny javascript and jQuery date / time picker [datepicker]
http://www.dematte.at/tinyDatePicker/
MIT License
57 stars 14 forks source link

Only timepicker init #2

Closed Sunsvision closed 8 years ago

Sunsvision commented 8 years ago

Hello! Is it possible to use timepicker only when there are no init value in the input? Unfortunately I did not find info about such option. Thanks for the great plugin!

PitPik commented 8 years ago

Hi @Sunsvision , thanks for your interest in date/time picker :) (and sorry for the mail flood while cleaning up comments).

Unfortunately there is no built in option but with the following instructions this is easily possible:

Just make your own data-type attribute:

<input class="date" value="" data-type="time" />

and use the following options:

window.myDatePicker = new DatePicker('.date', {
    readValue: function(element) {
        if (!element.value && element.getAttribute('data-type') === 'time') {
            return new Date().toTimeString().split(' ')[0]; // triggers default behavior
        }

        return element.value; // triggers default behavior
    }
};

You probably see that with this technique you're quite flexible in what you want to do. You can also make your own rules for how to pick up formats...

Sunsvision commented 8 years ago

Elegant solution, thanks a lot!