John Hughes
John Hughes

Reputation: 377

Disable datepicker if type=date supported

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?

Upvotes: 1

Views: 759

Answers (1)

John Hughes
John Hughes

Reputation: 377

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

if (!Modernizr.inputtypes.date)
{
    $("input[type=date]").datepicker();
}

Upvotes: 1

Related Questions