Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE Input type Date not appearing as Date Picker [duplicate]

I am using the input type DATE in my HTML and everything works fine in Chrome and Firefox, but IE does not show the date picker.

When I use the JQuery Datepicker I get two date picker dialogs in Chrome and Firefox.

How can I fix the functionality where I can have the date input type and only have one popup for my form?

like image 658
Robbye Rob Avatar asked Jun 17 '15 13:06

Robbye Rob


People also ask

How do you change the input type date in dd-mm-yyyy format?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.

How do I restrict input type date?

Approach: First, we need to write the code for input, and we need to give its type as the date in the HTML file. Then in-order to restrict the user to enter the date manually we can use onkeydown event. In the onkeydownevent we need to return false so that we can restrict the user to enter the date manually.

Does Safari support input type date?

Safari does not support the HTML5 date and time input types: https://caniuse.com/#feat=input-datetime.


1 Answers

You need to use a polyfill so that the input type DATE has a consistent behaviour in all browsers. You can use this webshim as a polyfill.

Input type DATE is an HTML5 feature which is not supported by all browsers. In case you want to use the HTML5 feature not supported by your browser (which usually will be IE) then use two things:

  • Feature Detection
  • Polyfills

Feature Detection is the ability to determine if the HTML5 feature is supported or not by our browser. A good library for that is Modernizr. What you can do with modernizr is to detect if any feature that you need is not supported and if not then you can conditionally load some javascript libraries that will implement that feature. Those libraries are called Polyfills.

So for example if you want to use the tag in IE 10 you could use the jqueryui.com controls to provide a date picker.

Modernizr.load({
    test: Modernizr.inputtypes.date,
    nope: "js/jquery-ui.custom.js",
    callback: function() {
      $("input[type=date]").datepicker();
    }
  });

Modernizr tests if the feature is supported, optionally you can use the nope to indicate if there is a library that you want to load ONLY if the feature is not supported, and callback is the code that will be called after the test and after loading the library.

like image 135
sam100rav Avatar answered Nov 11 '22 18:11

sam100rav