Skip to content

Instantly share code, notes, and snippets.

@MatthewSteeples
Created March 19, 2014 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthewSteeples/9633296 to your computer and use it in GitHub Desktop.
Save MatthewSteeples/9633296 to your computer and use it in GitHub Desktop.
@model DateTime?
@{
string name = ViewData.TemplateInfo.HtmlFieldPrefix;
string id = name.Replace(".", "_");
bool monthEndOnly = ViewBag.MonthEndOnly ?? false;
}
@Html.TextBoxFor(model => model, new { style = "DatePicker" })
<i class="icon-calendar"></i>
<script type="text/javascript">
$(function () {
$("#@id").datepicker({
@if (monthEndOnly)
{
<text>
beforeShowDay: function(date)
{
// getDate() returns the day [ 0 to 31 ]
if (date.getDate() ==
(new Date((new Date(date.getFullYear(), date.getMonth() + 1, 1)) - 1)).getDate())
{
return [true, ''];
}
return [false, ''];
},
</text>
}
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
showOn: "button"
});
$("#@id").val($("#@id").val().substring(0, 10));
$("#@id").addClass("dateITA");
$(".icon-calendar").click(function() {
$(this).prev(".ui-datepicker-trigger").click();
});
$("#@id").focus(function() {
return false;
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment