Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Once a DatePicker always a DatePicker

Once a DatePicker always a DatePicker

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++cssasp-netdesignjson
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brady Kelly
    wrote on last edited by
    #1

    After finding this ultra-cool Bootstrap `DateTimePicker`, I thought I could simply select all my date-pickers by class, and apply the relevant code for the `DateTimePicker`, and I’d have elegant and working date-time pickers all over. That was during that usual “honeymoon” period when you’ve just found a really cool hammer and can only see nails. That period passes quite quickly and then we’re left to deal with little niggly wrinkles to iron out on your new widget. The first and biggest is that MVC “has already” turned one of my date-time inputs into a built-in browser native date picker. On Edge and Chrome the built-in picker is usable, but not good UX and somewhat unintuitive. I don’t know how other browsers present date and time pickers. If a model property is of `DateTime`, MVC scaffolds an input with type `datetime-local`, and lets the browser deal with the rest. The code to initialize the DateTimePicker is normally simple, just call on your date-time input, like this:

    $(".date-picker").datetimepicker();

    Now when I did that, something weird happened. When I clicked any date-picker (input with class `date-picker`), I’d see two date-pickers: My new fancy one in the background, and overlaid on top of that, the browser date-picker – in my case Edge. I have to first make the input a normal text input, and then the fancy DateTimePicker, for things to work as wanted, with the 3rd party date-picker in charge:

    $(".date-picker").attr("type", "text");
    $(".date-picker").datetimepicker();
    

    Now I have one last “little” problem. When I click on one of my date-picklers, I get a history dropdown of recently used dates, but I suspect it is the browser’s date-picker doing this, because it drops down over my date-picker rendering it useless. Fortunately, a second click shows my date-picker without the dropdown.

    "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

    K Richard DeemingR 2 Replies Last reply
    0
    • B Brady Kelly

      After finding this ultra-cool Bootstrap `DateTimePicker`, I thought I could simply select all my date-pickers by class, and apply the relevant code for the `DateTimePicker`, and I’d have elegant and working date-time pickers all over. That was during that usual “honeymoon” period when you’ve just found a really cool hammer and can only see nails. That period passes quite quickly and then we’re left to deal with little niggly wrinkles to iron out on your new widget. The first and biggest is that MVC “has already” turned one of my date-time inputs into a built-in browser native date picker. On Edge and Chrome the built-in picker is usable, but not good UX and somewhat unintuitive. I don’t know how other browsers present date and time pickers. If a model property is of `DateTime`, MVC scaffolds an input with type `datetime-local`, and lets the browser deal with the rest. The code to initialize the DateTimePicker is normally simple, just call on your date-time input, like this:

      $(".date-picker").datetimepicker();

      Now when I did that, something weird happened. When I clicked any date-picker (input with class `date-picker`), I’d see two date-pickers: My new fancy one in the background, and overlaid on top of that, the browser date-picker – in my case Edge. I have to first make the input a normal text input, and then the fancy DateTimePicker, for things to work as wanted, with the 3rd party date-picker in charge:

      $(".date-picker").attr("type", "text");
      $(".date-picker").datetimepicker();
      

      Now I have one last “little” problem. When I click on one of my date-picklers, I get a history dropdown of recently used dates, but I suspect it is the browser’s date-picker doing this, because it drops down over my date-picker rendering it useless. Fortunately, a second click shows my date-picker without the dropdown.

      "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      somehow weired. Is the code correct? :confused:

      Press F1 for help or google it. Greetings from Germany

      B 1 Reply Last reply
      0
      • K KarstenK

        somehow weired. Is the code correct? :confused:

        Press F1 for help or google it. Greetings from Germany

        B Offline
        B Offline
        Brady Kelly
        wrote on last edited by
        #3

        What code? My little two lines of JS that fix things? There is no other code involved in this problem.

        1 Reply Last reply
        0
        • B Brady Kelly

          After finding this ultra-cool Bootstrap `DateTimePicker`, I thought I could simply select all my date-pickers by class, and apply the relevant code for the `DateTimePicker`, and I’d have elegant and working date-time pickers all over. That was during that usual “honeymoon” period when you’ve just found a really cool hammer and can only see nails. That period passes quite quickly and then we’re left to deal with little niggly wrinkles to iron out on your new widget. The first and biggest is that MVC “has already” turned one of my date-time inputs into a built-in browser native date picker. On Edge and Chrome the built-in picker is usable, but not good UX and somewhat unintuitive. I don’t know how other browsers present date and time pickers. If a model property is of `DateTime`, MVC scaffolds an input with type `datetime-local`, and lets the browser deal with the rest. The code to initialize the DateTimePicker is normally simple, just call on your date-time input, like this:

          $(".date-picker").datetimepicker();

          Now when I did that, something weird happened. When I clicked any date-picker (input with class `date-picker`), I’d see two date-pickers: My new fancy one in the background, and overlaid on top of that, the browser date-picker – in my case Edge. I have to first make the input a normal text input, and then the fancy DateTimePicker, for things to work as wanted, with the 3rd party date-picker in charge:

          $(".date-picker").attr("type", "text");
          $(".date-picker").datetimepicker();
          

          Now I have one last “little” problem. When I click on one of my date-picklers, I get a history dropdown of recently used dates, but I suspect it is the browser’s date-picker doing this, because it drops down over my date-picker rendering it useless. Fortunately, a second click shows my date-picker without the dropdown.

          "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Brady Kelly wrote:

          I don’t know how other browsers present date and time pickers.

          Can I use... Date and time input types[^] <input type="date"> - HTML | MDN[^] IE, Firefox and Safari currently don't support them at all. Support is apparently being added in Firefox 57.

          Brady Kelly wrote:

          $(".date-picker").attr("type", "text");

          That's going to break in old versions of IE - v8 and earlier, IIRC. If you need to support those older versions, you need to replace the <input> element, rather than changing its type.

          Brady Kelly wrote:

          When I click on one of my date-picklers, I get a history dropdown of recently used dates,

          Sounds like you need to disable autocomplete. Add autocomplete="off" to the attributes:

          @Html.EditorFor(m => m.YourDateField, new { htmlAttributes = new { autocomplete = "off" } })

          It would probably be easier to create a custom editor template for DateTime values: ASP.NET MVC display and editor templates - Growing with the Web[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          B 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Brady Kelly wrote:

            I don’t know how other browsers present date and time pickers.

            Can I use... Date and time input types[^] <input type="date"> - HTML | MDN[^] IE, Firefox and Safari currently don't support them at all. Support is apparently being added in Firefox 57.

            Brady Kelly wrote:

            $(".date-picker").attr("type", "text");

            That's going to break in old versions of IE - v8 and earlier, IIRC. If you need to support those older versions, you need to replace the <input> element, rather than changing its type.

            Brady Kelly wrote:

            When I click on one of my date-picklers, I get a history dropdown of recently used dates,

            Sounds like you need to disable autocomplete. Add autocomplete="off" to the attributes:

            @Html.EditorFor(m => m.YourDateField, new { htmlAttributes = new { autocomplete = "off" } })

            It would probably be easier to create a custom editor template for DateTime values: ASP.NET MVC display and editor templates - Growing with the Web[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            B Offline
            B Offline
            Brady Kelly
            wrote on last edited by
            #5

            Thanks for all the info. I suppose I should test on more than just Edge and Firefox, but it's a hobby project. I don't care if anything IE8 or prior breaks, so replacing the type is good for me, but the best is the autocomplete. I never knew there was such and attribute, thanks. It has crossed my mind several times to use a template, but I want to get the rendered HTML correct first.

            "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups