asp.net mvc 3 - Determining if a date field presents a calendar popup via JavaScript -


for mvc app working on, have date fields on page.

my initial reaction use jquery ui's datepicker, hit small snag - we're expecting application run on ipads. so, asked using html5 <input type="date" /> tag, fall datepicker if browser dosen't support it.

one additional small problem: ie evil.

apparently, ie does 'support' <input type="date" />; dosen't show calendar when clicked.

a abbreviated, sanitized markup:

@* in html body... *@ @html.inputfor(m => m.somedate, new { id="a", type="date" }) @html.inputfor(m => m.someotherdate, new { id="b", type="date" })  <script> var $a = $('#a'),     $b = $('#b');  $(document).ready(function () {   fallbacktodatepicker($a);   fallbacktodatepicker($b);    @* ...snip: other operations here... *@ });  function fallbacktodatepicker($field) {   if($field.type() != "date") {     console.log($field.selector + " not date field!");     $field.datepicker();   } } </script> 

(solution based on: http://www.javascriptkit.com/javatutors/createelementcheck2.shtml)

the problem trying solve determine if client running browser not have native calendar popup <input type="date" />; if client running on such browser, need fallback datepicker.

question: more accurate, still elegant/programmatic way of determining if client browser supports date popup?

(a note: recommending team abandon date-input silliness, , use datepicker.)


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -