I am trying to get my MVC3, EF4 project to work with the javascript datepicker, but I am running into issues as I want the date to be in the UK format (dd/mm/yyyy).
I have spent several hours researching this issue and I have decided to implement the 'globalize' library scripts as I have seen in this link.
However I am getting a Uncaught TypeError: Cannot read property 'methods' of undefined
in the javascript (coming from the $.validator.methods.date
line) when I run it. My knowledge of javascript is pretty limited and all the examples I have found that use the 'globalize' library have no mention of this error and therefore I am quite stumped.
I have shown the relevant code from my view below:
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.globalize/globalize.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.globalize/cultures/globalize.culture.en-GB.js")" type="text/javascript"></script>
<link href="../../Content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
Globalize.culture("en-GB");
$.validator.methods.date = function (value, element) { return this.optional(element) || Globalize.parseDate(value); }
</script>
<script type="text/javascript">
$(document).ready(function () {
$('.date').datepicker({ dateFormat: "dd/mm/yy" });
});
</script>
//SNIP
<div class="editor-field">
@Html.TextBox("Expires", Model.Expires, new { @class = "date" })
@Html.ValidationMessageFor(model => model.Expires)
</div>
Could someone please help me fix this issue.
Thanks very much.