I have an HTML form that includes type = date fields. Each date field has a minimum / maximum value set as a basic sanity check, as my users prefer to enter a form (rather than using date pickers), and they often enter dates like "4/17/0213".
The form is submitted by calling jquery ajax, which is launched by the submit form.
All users use Chrome as a browser.
When they enter the date completely, which is out of range, checking the date range works as it should. When they simply change the year or year and another part of the date (month or day, but not both) to the existing date so that it ends outside the valid range, Chrome does not give them a validation error. Instead, he silently "corrects" a year ago to what was previously, so that he remains in the valid date range. This causes the garbage values to be silently received into the database.
I tried to write my own validation procedure in javascript, but it seems that the problem is that the underlying value of the data does not change until the invalid year, so trying to get it and verify that it is a waste of time. As for Chrome, the wrong year was simply not entered.
Does anyone know a workaround for this?
EDIT: I included some code to demonstrate part of the problem.
<!DOCTYPE HTML>
<html>
<head>
<title>Date bug test</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
$(document).on("submit", "FORM", function(){
$("#dateshow").html("Date entered was: " + $("input[name=foo]").val());
return true;
});
});
</script>
</head>
<body>
<form action="javascript:void(0)">
<input type=date name="foo" min='1980-01-01' max='2080-01-01' />
<input type=text name="bar">
<input type=submit>
</form>
<div id=dateshow></div>
</body>
To demonstrate:
- Save this in html file and open in Chrome
- Enter the date from 1980 to 2080 in the date field and send
- The date will be displayed as presented.
- Select ONLY YEAR in the date field and change it to a value outside the valid range
- Click the "Submit" button again.
- Please note that the date presented does not change, although your invalid date is still displayed in the form control.
source
share