PitPik / tinyDatePicker

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

Displaying time only when no initial data #6

Closed chriscarpenter12 closed 7 years ago

chriscarpenter12 commented 7 years ago

Is there a way to display time only when no initial data is in the form?

The white example has a time field. If you remove the data, click outside to clear the time picker and click back it shows a calendar instead of a time picker.

I see on your main page demo it also has a time picker which has data-type="time" set, but that doesn't seem to be working for me to force the input to be time picker only.

chriscarpenter12 commented 7 years ago

I figured it out. Looked at the source on the main demo page. You used readValue function.

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

  return element.value; // triggers default behavior
}