PitPik/tinyDatePicker

Only timepicker init

Closed this issue · 2 comments

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!

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...

Elegant solution, thanks a lot!