Last active
November 18, 2016 15:06
-
-
Save dgibson666/cfbf6b8ae3224072872aaffb814a3898 to your computer and use it in GitHub Desktop.
HTML5 Date Inputs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="date" name="inspectionStart" value="#Dateformat(somedate,"yyyy-mm-dd")#"> | |
<script> | |
$(document).ready(function () { | |
// If a browser doesn't support HTML5 date input types, then load a backup/polyfill | |
if(!Modernizr.inputtypes.date){ | |
// Convert the format from the HTML5 dateformat of yyyy-mm-dd to mm/dd/yyyy | |
$('input[type=date]').each(function(){ | |
var thisdate=$(this).val(); | |
if(thisdate.length){ | |
var dateparts=thisdate.split('-'); | |
var newdate=dateparts[1]+'/'+dateparts[2]+'/'+dateparts[0]; | |
$(this).val(newdate); | |
} | |
}); | |
// Call the jQueryUI datepicker and use the same format as above | |
$('input[type=date]').datepicker({ | |
//dateFormat: 'yy-mm-dd' // HTML5 format | |
dateFormat: 'mm/dd/yy' | |
}); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment