locked
Is there a way to have a date or time be optional with the built in WinJS.UI datepicker and timepicker?

    Question

  • I need to create a fairly simple form where both a date and time input are optional.

    In traditional web, I would typically have the selected item of the day/month/year show something like "--/--/----" instead of defaulting to today's date.

    Is this possible with the built-in datepicker and timepicker?  If not, any detailed recommendations on the best approaceh?

    Thanks.

    -Keith

    Thursday, September 20, 2012 5:16 PM

Answers

  • Hi

    By my understanding, you can not use datepicker for that function, can you really needn't.

    Just use Jquery data picker, you can achieve that.

    1 create three textbox, and set value to --,--,----.

    2 find suitable jquery datapicker for each textbox.

    3 write the logic you want in your JS file.


    • Edited by Dino He Sunday, September 23, 2012 9:53 AM
    • Marked as answer by Dino He Thursday, October 11, 2012 8:07 AM
    Sunday, September 23, 2012 9:53 AM
  • I didn't think the time portion showed up by default.  You can hide the day portion using this CSS style

    .win-datepicker-date {
        display: none;
    }

    Just make sure you set the date to something when you initialize the picker (like 1), like in your page onReady.

    I agree with the roll your own comment by the way, a lot of this stuff is half-baked.

    • Marked as answer by Dino He Thursday, October 11, 2012 8:07 AM
    Wednesday, September 26, 2012 8:53 PM

All replies

  • Hi

    By my understanding, you can not use datepicker for that function, can you really needn't.

    Just use Jquery data picker, you can achieve that.

    1 create three textbox, and set value to --,--,----.

    2 find suitable jquery datapicker for each textbox.

    3 write the logic you want in your JS file.


    • Edited by Dino He Sunday, September 23, 2012 9:53 AM
    • Marked as answer by Dino He Thursday, October 11, 2012 8:07 AM
    Sunday, September 23, 2012 9:53 AM
  • I understand and know how to do that but what's the point in Microsoft providing a datepicker & a timepicker if I'm supposed to just roll my own for even the simplest of use cases?

    Wednesday, September 26, 2012 6:41 PM
  • I didn't think the time portion showed up by default.  You can hide the day portion using this CSS style

    .win-datepicker-date {
        display: none;
    }

    Just make sure you set the date to something when you initialize the picker (like 1), like in your page onReady.

    I agree with the roll your own comment by the way, a lot of this stuff is half-baked.

    • Marked as answer by Dino He Thursday, October 11, 2012 8:07 AM
    Wednesday, September 26, 2012 8:53 PM