Apologies for if the question is obvious but I can't figure out why it is suddenly not working. I have a jquery datepicker that has been working fine as long as I can remember, but all of a sudden, when I try to submit the form that the datepicker is on the datepicker reappears as though the date I am submitting is invalid. I have already set my date to uk style using the following line of code:
<script type="text/javascript">
$(document).ready(function () {
$('.date').datepicker({ dateFormat: "dd/mm/yy", minDate: 0 });
});
</script>
And I setup the datepicker in my view like this:
@Html.TextBox("DateDue", "", new { @class = "date" })
I think that something is requiring the datestring selected to be in US format (as it will submit a valid us date (mm/dd/yyyy) but not the UK format, even though it has been set in the javascript.
Am I missing something obvious? Could anyone tell me what I'm doing wrong here?
Am not sure if it is necessary but the form that the datepicker is on is created like this:
@using (
Html.BeginForm(
Html.BeginForm(
"Create",
"Task",
FormMethod.Post,
new { id = "taskCreateForm" }
)
)
)
PS. The datestring actually works and posts without a problem in Firefox but not in Chrome
Any help appreciated
EDIT:
The problem goes away when I disable the unobtrusive js validation:
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"
type="text/javascript"></script>
I had a feeling it was something to do with this and tried remoing the [Required] and [DataType(DataType.Date)] from the model annotation but this didn't do the trick.
Not sure how to leave the unobtrusive js in as well as have the uk date string working ok, but am more and more turning to write my own javascript validation for forms than to even bother with the built in stuff, which never seems to work for anything more complicated than a 'required' validation check..