1

I have a jQuery date picker install on several of my web pages using MVC. As such type="date" is added to the control.

  1. If using IE11 or less the jQuery control shows correctly.
  2. If using Firefox 42 the jQuery control shows correctly.
  3. If using MS-Edge I get the Edge date picker plus the jQuery date picker.
  4. If using Chrome I get both date pickers.
  5. If using Safari (Windows) I get something, I am not sure what it is.
  6. Some mobile device do a combination of the above.

So where I agree with the general consensus that browser select is wrong and really don't want to guess on which browsers support what, I do need a solution.

Is there a way to determine if the browser has it's own date picker?

Basically I want to turn off the jquery datepicker if the browser supports it and turn it on if it does not.

The other thing I was thinking was to add a date picker button so the user can either use the default if it works on click the button if they want or need the jQuery date picker. This way at least the two options are not competing.

Suggestion?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
John Hughes
  • 367
  • 1
  • 3
  • 20
  • try using modernizr lib then. – Jai Jan 08 '16 at 13:56
  • my project has modernizr-2.8.3 installed, how does that help me? Or I guess the better question is how do I use it in this case? – John Hughes Jan 08 '16 at 14:02
  • you can check if browser supports the type date element if it does not then replace it with type texxt and use datepicker. – Jai Jan 08 '16 at 14:05
  • 1
    `if(Modernizr.inputtypes.date) { //supports } else { //datepicker};` – Tamil Selvan C Jan 08 '16 at 14:12
  • Possible duplicate of [How can I tell if a browser supports ](http://stackoverflow.com/questions/10193294/how-can-i-tell-if-a-browser-supports-input-type-date) – blgt Jan 08 '16 at 14:15
  • Yes Tamil, that answered the question but better then blgt link which does not. – John Hughes Jan 08 '16 at 14:41
  • blgt... in concept the question you refer to maybe similar I am not able to get the correct answer from it so I don't see where it is useful but thanks for pointing it out. – John Hughes Jan 08 '16 at 14:45

1 Answers1

1

As Tamil Selvan pointed out in his comment.
This is how I got it to work.

if (!Modernizr.inputtypes.date)
{
    $("input[type=date]").datepicker();
}
John Hughes
  • 367
  • 1
  • 3
  • 20