Browse files

better handling of min/max dates in selectors

  • Loading branch information...
1 parent 66b187a commit 85655d7a15d649ab2ccde018a93e75214aa271e6 @tipiirai tipiirai committed Sep 22, 2010
Showing with 14 additions and 22 deletions.
  1. +1 −1 build.xml
  2. +10 −16 src/dateinput/dateinput.js
  3. +3 −5 test/dateinput/setmin.htm
View
2 build.xml
@@ -1,7 +1,7 @@
<project name="jQuery.Tools" default="min">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
- <property name="version" value="1.2.4"/>
+ <property name="version" value="1.2.5"/>
<property name="build" value="build/${version}"/>
<property name="file" value="none"/>
View
26 src/dateinput/dateinput.js
@@ -457,24 +457,18 @@
//{{{ setValue
- setValue: function(year, month, day) {
+ setValue: function(year, month, day) {
+ var date = integer(month) >= -1 ?
+ new Date(integer(year), integer(month), integer(day || 1)) : year || value
+ ;
- var date;
-
- if (parseInt(month, 10) >= -1) {
- // strings to numbers
- year = integer(year);
- month = integer(month);
- day = integer(day);
- date = new Date(year, month, day);
-
- } else {
- date = year || value;
- year = date.getFullYear();
- month = date.getMonth();
- day = date.getDate();
- }
+ if (date < min) { date = min; }
+ else if (date > max) { date = max; }
+
+ year = date.getFullYear();
+ month = date.getMonth();
+ day = date.getDate();
// roll year & month
View
8 test/dateinput/setmin.htm
@@ -5,14 +5,12 @@
<link rel="stylesheet" type="text/css" href="skin1.css"/>
<!-- HTML5 date input -->
-<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" />
+<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" max="2011-12-02" />
-<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" />
+<input type="date" name="mydate" data-value="2010-12-01" min="2010-12-01" max="2012-07-01" />
<!-- make it happen -->
<script>
-$(":date:first").dateinput({selectors: true});
-
-$(":date:last").dateinput({selectors: false});
+$(":date").dateinput({selectors: true});
</script>

0 comments on commit 85655d7

Please sign in to comment.