Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-browser datepicker component (compatible with mobile and desktop browsers) and with Bootstrap

is there any datepicker library that would work in mobile browsers (Android, iOS, Windows phone) and also in standard browsers? It would be perfect if it were compatible with Bootstrap css, and if it could fall-back to native html5 date fields where possible. Please recommend something. I tried - webshims (broken in Android and IE) - pickadate (not happy with how it behaves)

like image 364
nightwatch Avatar asked Sep 15 '15 22:09

nightwatch


1 Answers

JQuery UI is your friend here... and here is a sample

<head>
<script type="text/javascript">
    var datefield=document.createElement("input")
    datefield.setAttribute("type", "date")
    if (datefield.type!="date"){ //if browser doesn't support input type="date", load files for jQuery UI Date Picker
        document.write('<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />\n')
        document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"><\/script>\n')
        document.write('<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"><\/script>\n') 
}
</script>

<script>
if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget:
    jQuery(function($){ //on document.ready
        $('#birthday').datepicker();
    })
}
</script>
</head>

<body>
    <form>
        <b>Date of birth:</b>
        <input type="date" id="birthday" name="birthday" size="20" />
        <input type="button" value="Submit" name="B1"></p>
    </form>
</body>
like image 181
FrickeFresh Avatar answered Nov 15 '22 05:11

FrickeFresh